,因為它不是普通指針,而是一個數組。它重載了[],可以像使用數組下標那樣訪問數組。#ifndef BOOST_SMA">

多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > Boost源碼學習---scoped_array.hpp

Boost源碼學習---scoped_array.hpp

來源:程序員人生   發布時間:2014-10-11 08:00:01 閱讀次數:2518次
scoped_array功能類似scoped_ptr,scoped_array管理的是new[]開辟的數組,其析構函數調用的是delete[]釋放數組。

它沒有重載解引用*和箭頭操作符->,因為它不是普通指針,而是一個數組。它重載了[],可以像使用數組下標那樣訪問數組。

#ifndef BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED #define BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. // Copyright (c) 2001, 2002 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) // // 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_t namespace 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 extends 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; void operator==( scoped_array const& ) const; void operator!=( scoped_array const& ) const; public: typedef T element_type; explicit scoped_array( T * p = 0 ) BOOST_NOEXCEPT : px( p ) { #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) 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_NOEXCEPT) { BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors this_type(p).swap(*this); } //重載[],可以像訪問數組一樣訪問其元素 T & operator[](std::ptrdiff_t i) const // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT) { BOOST_ASSERT( px != 0 ); BOOST_ASSERT( i >= 0 ); return px[i]; } T * get() const BOOST_NOEXCEPT { return px; } // implicit conversion to "bool" #include <boost/smart_ptr/detail/operator_bool.hpp> void swap(scoped_array & b) BOOST_NOEXCEPT { 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_NOEXCEPT { return p.get() == 0; } template<class T> inline bool operator==( boost::detail::sp_nullptr_t, scoped_array<T> const & p ) BOOST_NOEXCEPT { return p.get() == 0; } template<class T> inline bool operator!=( scoped_array<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT { return p.get() != 0; } template<class T> inline bool operator!=( boost::detail::sp_nullptr_t, scoped_array<T> const & p ) BOOST_NOEXCEPT { return p.get() != 0; } #endif template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) BOOST_NOEXCEPT { a.swap(b); } } // namespace boost #endif // #ifndef BOOST_SMART_PTR_SCOPED_ARRAY_HPP_INCLUDED


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 法国性xxxxx极品 | 经典三级一区二区三区视频 | 有码一区 | 日本一区二区高清不卡 | 美国爱爱片视频在线观看 | 成人三级精品视频在线观看 | 色人阁视频 | 一级久久久 | 伊人网在线视频 | 最新亚洲精品国自产在线观看 | 亚洲色播永久网址大全 | 久久精品久久精品国产大片 | 久操精品| 成人亚洲精品一区二区 | jizz性欧美3| 亚洲天堂在线视频播放 | 在线视频一区二区三区 | 国产一区日韩二区欧美三 | 久久久日本精品一区二区三区 | 欧美另类videosbestse | 免费国产精成人品 | 国产精品中文字幕在线 | 日韩精品亚洲人成在线观看 | 亚洲精品国自产拍在线观看 | 91午夜精品亚洲一区二区三区 | 一级特黄女人生活片 | 日本高清www | 日韩影院在线 | 永久在线播放 | 日本vs黑人hd | 成人性色生活片免费看爆迷你毛片 | 国产三级第一页 | 国产一区二区三区在线免费 | 亚洲天堂免费在线 | 在线观看麻豆精品国产不卡 | 老司机午夜免费 | 波多野结衣亚洲一区二区三区 | 国产操操操 | 国产片在线看 | 麻豆影 | 在线播放免费一级毛片欧美 |