• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            boost/checked_delete.hpp

            Posted on 2009-06-22 13:26 天邊藍 閱讀(588) 評論(0)  編輯 收藏 引用 所屬分類: boost學習

             

             1#ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED
             2#define BOOST_CHECKED_DELETE_HPP_INCLUDED
             3
             4// MS compatible compilers support #pragma once
             5
             6#if defined(_MSC_VER) && (_MSC_VER >= 1020)
             7# pragma once
             8#endif
             9
            10//
            11//  boost/checked_delete.hpp
            12//
            13//  Copyright (c) 2002, 2003 Peter Dimov
            14//  Copyright (c) 2003 Daniel Frey
            15//  Copyright (c) 2003 Howard Hinnant
            16//
            17//  Distributed under the Boost Software License, Version 1.0. (See
            18//  accompanying file LICENSE_1_0.txt or copy at
            19//  http://www.boost.org/LICENSE_1_0.txt)
            20//
            21//  See http://www.boost.org/libs/utility/checked_delete.html for documentation.
            22//
            23
            24namespace boost
            25{
            26
            27// verify that types are complete for increased safety
            28
            29template<class T> inline void checked_delete(T * x)
            30{
            31    // intentionally complex - simplification causes regressions
            32    typedef char type_must_be_complete[ sizeof(T)? 1-1 ];
            33    (voidsizeof(type_must_be_complete);
            34    delete x;
            35}

            36
            37template<class T> inline void checked_array_delete(T * x)
            38{
            39    typedef char type_must_be_complete[ sizeof(T)? 1-1 ];
            40    (voidsizeof(type_must_be_complete);
            41    delete [] x;
            42}

            43
            44template<class T> struct checked_deleter
            45{
            46    typedef void result_type;
            47    typedef T * argument_type;
            48
            49    void operator()(T * x) const
            50    {
            51        // boost:: disables ADL
            52        boost::checked_delete(x);
            53    }

            54}
            ;
            55
            56template<class T> struct checked_array_deleter
            57{
            58    typedef void result_type;
            59    typedef T * argument_type;
            60
            61    void operator()(T * x) const
            62    {
            63        boost::checked_array_delete(x);
            64    }

            65}
            ;
            66
            67}
             // namespace boost
            68
            69#endif  // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED


            ------------------------------------
            source:http://www.boost.org/doc/libs/1_39_0/libs/utility/checked_delete.html

            The header <boost/checked_delete.hpp> defines two function templates, checked_delete and checked_array_delete, and two class templates, checked_deleter and checked_array_deleter.

            The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to be deleted with a delete-expression. When the class has a non-trivial destructor, or a class-specific operator delete, the behavior is undefined. Some compilers issue a warning when an incomplete type is deleted, but unfortunately, not all do, and programmers sometimes ignore or disable warnings.

            A particularly troublesome case is when a smart pointer's destructor, such as boost::scoped_ptr<T>::~scoped_ptr, is instantiated with an incomplete type. This can often lead to silent, hard to track failures.

            The supplied function and class templates can be used to prevent these problems, as they require a complete type, and cause a compilation error otherwise.

            Synopsis

             1namespace boost
             2{
             3
             4template<class T> void checked_delete(T * p);
             5template<class T> void checked_array_delete(T * p);
             6template<class T> struct checked_deleter;
             7template<class T> struct checked_array_deleter;
             8
             9}

            10
            11checked_delete
            12template<class T> void checked_delete(T * p);
            13
            14


            Requires: T must be a complete type. The expression delete p must be well-formed.

            Effects: delete p;

             

             1checked_array_delete
             2template<class T> void checked_array_delete(T * p);
             3Requires: T must be a complete type. The expression delete [] p must be well-formed. 
             4
             5Effects: delete [] p; 
             6
             7checked_deleter
             8template<class T> struct checked_deleter
             9{
            10    typedef void result_type;
            11    typedef T * argument_type;
            12    void operator()(T * p) const;
            13}
            ;
            14
            15void checked_deleter<T>::operator()(T * p) const;
            16
            17


            Requires: T must be a complete type. The expression delete p must be well-formed.

            Effects: delete p;

             

             1checked_array_deleter
             2template<class T> struct checked_array_deleter
             3{
             4    typedef void result_type;
             5    typedef T * argument_type;
             6    void operator()(T * p) const;
             7}
            ;
             8
             9void checked_array_deleter<T>::operator()(T * p) const;
            10


            Requires: T must be a complete type. The expression delete [] p must be well-formed.

            Effects: delete [] p;

            Acknowledgements
            The function templates checked_delete and checked_array_delete were originally part of <boost/utility.hpp>, and the documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, Rainer Deyke, John Maddock, and others as contributors.


            Copyright © 2002 by Peter Dimov. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.

            Copyright © 天邊藍

            久久青青草原亚洲av无码app| 亚洲国产另类久久久精品小说| 精品无码久久久久久久动漫| 色诱久久av| 无码精品久久久天天影视| 国产精品青草久久久久福利99| 久久久久亚洲精品日久生情| 久久伊人精品青青草原高清| 97久久国产综合精品女不卡| 久久精品国产精品青草| 久久人妻少妇嫩草AV蜜桃| 99久久精品久久久久久清纯| 久久亚洲私人国产精品vA| 久久亚洲高清综合| 99精品久久久久久久婷婷| 亚洲女久久久噜噜噜熟女| 精品久久综合1区2区3区激情| 久久亚洲精品成人AV| 亚洲精品99久久久久中文字幕 | 亚洲精品第一综合99久久| 国产成人精品久久亚洲高清不卡 | 中文字幕亚洲综合久久2| 亚洲国产精品18久久久久久| 一本色道久久综合狠狠躁篇| 久久久久这里只有精品| 国内精品久久久久久不卡影院 | 久久久精品国产sm调教网站| 久久久这里有精品| 亚洲综合久久久| 久久婷婷人人澡人人爽人人爱| 久久亚洲国产成人精品无码区| 国产免费久久精品丫丫| 99久久精品费精品国产| 国产日韩欧美久久| 久久精品国产亚洲5555| 久久精品女人天堂AV麻| 久久精品夜色噜噜亚洲A∨| 国产毛片久久久久久国产毛片| 国产精品熟女福利久久AV| 精品久久久久久无码中文野结衣| 国产午夜福利精品久久|