Boost source code learning ---

Source: Internet
Author: User
Scoped_array is similar to scoped_ptr. scoped_array manages arrays opened in new []. Its destructor calls Delete [] to release arrays.

It does not reload the unreferenced * and arrow operators->, because it is not a common pointer, but an array. It reloads [] and can access the array as it uses the array subscript.

# Ifndef boost_smart_ptr_scoped_array_hpp_included # define boost_smart_ptr_scoped_array_hpp_included // (c) Copyright Greg Colvin and beman Dawes 1998,199 9. // copyright (c) 2001,200 2 Peter DIMOV /// distributed under the boost software license, Version 1.0. (See // accompanying file license_00000.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) /// http://www.boost.org/libs/smart_ptr/scoped_array. Htm // # include <boost/config. HPP> # include <boost/assert. HPP> # include <boost/checked_delete.hpp> # include <boost/smart_ptr/detail/sp_nullptr_t.hpp> # include <boost/detail/workaround. HPP> # include <cstddef> // for STD: ptrdiff_tnamespace boost {// debug hooks # If defined (boost_sp_enable_debug_hooks) void sp_array_constructor_hook (void * P ); void sp_array_destructor_hook (void * P); # endif // scoped_array exte NDS scoped_ptr to arrays. deletion of the array pointed to // is guaranteed, either on destruction of the scoped_array or via an explicit // reset (). use shared_array or STD: vector if your needs are more complex. template <class T> class scoped_array // noncopyable {PRIVATE: T * PX; scoped_array (scoped_array const &); scoped_array & operator = (scoped_array const &); typedef scoped_array <t> this_type; V Oid operator = (scoped_array const &) const; void Operator! = (Scoped_array const &) const; public: typedef t element_type; explicit scoped_array (T * p = 0) boost_no1_t: Px (p) {# If defined (SUCCESS) boost :: sp_array_constructor_hook (PX); # endif }~ Scoped_array () // never throws {# If defined (boost_sp_enable_debug_hooks) boost: sp_array_destructor_hook (PX); # endif boost: checked_array_delete (PX );} void reset (T * p = 0) // never throws (but has a boost_assert in it, so not marked with boost_no1_t) {boost_assert (P = 0 | P! = Px); // catch self-Reset errors this_type (P ). swap (* This);} // reload [] to access its element T & operator [] (STD: ptrdiff_t I) Just like an array) const // never throws (but has a boost_assert in it, so not marked with boost_no1_t) {boost_assert (PX! = 0); boost_assert (I> = 0); Return PX [I];} t * Get () const boost_no1_t {return PX ;} // implicit conversion to "bool" # include <boost/smart_ptr/detail/operator_bool.hpp> void swap (scoped_array & B) boost_no1_t {T * TMP = B. px; B. px = px; PX = TMP ;};# if! Defined (boost_no_cxx11_nullptr) template <class T> inline bool operator = (scoped_array <t> const & P, boost: detail: sp_nullptr_t) boost_no1_t {return p. get () = 0;} template <class T> inline bool operator = (boost: detail: sp_nullptr_t, scoped_array <t> const & P) boost_no1_t {return p. get () = 0;} template <class T> inline bool Operator! = (Scoped_array <t> const & P, boost: detail: sp_nullptr_t) boost_no1_t {return P. Get ()! = 0;} template <class T> inline bool Operator! = (Boost: detail: sp_nullptr_t, scoped_array <t> const & P) boost_no1_t {return P. Get ()! = 0 ;}# endiftemplate <class T> inline void swap (scoped_array <t> & A, scoped_array <t> & B) boost_no1_t {. swap (B) ;}}// namespace boost # endif // # ifndef boost_smart_ptr_scoped_array_hpp_included


Boost source code learning ---

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.