1 #ifndef BOOST_SMART_PTR_DETAIL_LOCAL_COUNTED_BASE_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_LOCAL_COUNTED_BASE_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
10 // detail/local_counted_base.hpp
12 // Copyright 2017 Peter Dimov
14 // Distributed under the Boost Software License, Version 1.0. (See
15 // accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
18 // See http://www.boost.org/libs/smart_ptr/ for documentation.
20 #include <boost/smart_ptr/detail/shared_count.hpp>
21 #include <boost/config.hpp>
30 class local_counted_base
34 local_counted_base & operator= ( local_counted_base const & );
38 // not 'int' or 'unsigned' to avoid aliasing and enable optimizations
39 enum count_type { min_ = 0, initial_ = 1, max_ = 2147483647 };
41 count_type local_use_count_;
45 BOOST_CONSTEXPR local_counted_base() BOOST_SP_NOEXCEPT: local_use_count_( initial_ )
49 BOOST_CONSTEXPR local_counted_base( local_counted_base const & ) BOOST_SP_NOEXCEPT: local_use_count_( initial_ )
53 virtual ~local_counted_base() /*BOOST_SP_NOEXCEPT*/
57 virtual void local_cb_destroy() BOOST_SP_NOEXCEPT = 0;
59 virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT = 0;
61 void add_ref() BOOST_SP_NOEXCEPT
63 #if !defined(__NVCC__)
64 #if defined( __has_builtin )
65 # if __has_builtin( __builtin_assume )
67 __builtin_assume( local_use_count_ >= 1 );
73 local_use_count_ = static_cast<count_type>( local_use_count_ + 1 );
76 void release() BOOST_SP_NOEXCEPT
78 local_use_count_ = static_cast<count_type>( local_use_count_ - 1 );
80 if( local_use_count_ == 0 )
86 long local_use_count() const BOOST_SP_NOEXCEPT
88 return local_use_count_;
92 class local_counted_impl: public local_counted_base
96 local_counted_impl( local_counted_impl const & );
104 explicit local_counted_impl( shared_count const& pn ): pn_( pn )
108 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
110 explicit local_counted_impl( shared_count && pn ): pn_( std::move(pn) )
116 virtual void local_cb_destroy() BOOST_SP_NOEXCEPT
121 virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT
127 class local_counted_impl_em: public local_counted_base
133 virtual void local_cb_destroy() BOOST_SP_NOEXCEPT
135 shared_count().swap( pn_ );
138 virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT
144 } // namespace detail
148 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LOCAL_COUNTED_BASE_HPP_INCLUDED