File indexing completed on 2025-12-16 09:43:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_ATOMIC_REF_HPP_INCLUDED_
0016
0017 #include <boost/assert.hpp>
0018 #include <boost/memory_order.hpp>
0019 #include <boost/atomic/capabilities.hpp>
0020 #include <boost/atomic/detail/config.hpp>
0021 #include <boost/atomic/detail/intptr.hpp>
0022 #include <boost/atomic/detail/classify.hpp>
0023 #include <boost/atomic/detail/atomic_ref_impl.hpp>
0024 #include <boost/atomic/detail/type_traits/is_trivially_copyable.hpp>
0025 #include <boost/atomic/detail/header.hpp>
0026
0027 #ifdef BOOST_HAS_PRAGMA_ONCE
0028 #pragma once
0029 #endif
0030
0031 namespace boost {
0032 namespace atomics {
0033
0034
0035 template< typename T >
0036 class atomic_ref :
0037 public atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, false >
0038 {
0039 private:
0040 typedef atomics::detail::base_atomic_ref< T, typename atomics::detail::classify< T >::type, false > base_type;
0041 typedef typename base_type::value_arg_type value_arg_type;
0042
0043 public:
0044 typedef typename base_type::value_type value_type;
0045
0046 static_assert(sizeof(value_type) > 0u, "boost::atomic_ref<T> requires T to be a complete type");
0047 #if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_IS_TRIVIALLY_COPYABLE)
0048 static_assert(atomics::detail::is_trivially_copyable< value_type >::value, "boost::atomic_ref<T> requires T to be a trivially copyable type");
0049 #endif
0050
0051 private:
0052 typedef typename base_type::storage_type storage_type;
0053
0054 public:
0055 BOOST_DEFAULTED_FUNCTION(atomic_ref(atomic_ref const& that) BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_DECL, BOOST_ATOMIC_DETAIL_DEF_NOEXCEPT_IMPL : base_type(static_cast< base_type const& >(that)) {})
0056 BOOST_FORCEINLINE explicit atomic_ref(value_type& v) BOOST_NOEXCEPT : base_type(v)
0057 {
0058
0059 BOOST_ASSERT((((atomics::detail::uintptr_t)this->m_value) & (base_type::required_alignment - 1u)) == 0u);
0060 }
0061
0062 BOOST_FORCEINLINE value_type operator= (value_arg_type v) const BOOST_NOEXCEPT
0063 {
0064 this->store(v);
0065 return v;
0066 }
0067
0068 BOOST_FORCEINLINE operator value_type() const BOOST_NOEXCEPT
0069 {
0070 return this->load();
0071 }
0072
0073 BOOST_DELETED_FUNCTION(atomic_ref& operator= (atomic_ref const&))
0074 };
0075
0076 #if !defined(BOOST_NO_CXX17_DEDUCTION_GUIDES)
0077 template< typename T >
0078 atomic_ref(T&) -> atomic_ref< T >;
0079 #endif
0080
0081
0082 template< typename T >
0083 BOOST_FORCEINLINE atomic_ref< T > make_atomic_ref(T& value) BOOST_NOEXCEPT
0084 {
0085 return atomic_ref< T >(value);
0086 }
0087
0088 }
0089
0090 using atomics::atomic_ref;
0091 using atomics::make_atomic_ref;
0092
0093 }
0094
0095 #include <boost/atomic/detail/footer.hpp>
0096
0097 #endif