forked from boostorg/smart_ptr
Make atomic_shared_ptr's default constructor constexpr
This commit is contained in:
@ -35,7 +35,7 @@ namespace boost {
|
||||
|
||||
public:
|
||||
|
||||
atomic_shared_ptr() noexcept = default;
|
||||
constexpr atomic_shared_ptr() noexcept;
|
||||
atomic_shared_ptr( shared_ptr<T> p ) noexcept;
|
||||
|
||||
atomic_shared_ptr& operator=( shared_ptr<T> r ) noexcept;
|
||||
@ -64,6 +64,14 @@ namespace boost {
|
||||
|
||||
## Members
|
||||
|
||||
```
|
||||
constexpr atomic_shared_ptr() noexcept;
|
||||
```
|
||||
[none]
|
||||
* {blank}
|
||||
+
|
||||
Effects:: Default-initializes `p_`.
|
||||
|
||||
```
|
||||
atomic_shared_ptr( shared_ptr<T> p ) noexcept;
|
||||
```
|
||||
|
@ -57,12 +57,22 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX ) && !defined( BOOST_NO_CXX11_CONSTEXPR )
|
||||
|
||||
constexpr atomic_shared_ptr() BOOST_SP_NOEXCEPT: l_ BOOST_DETAIL_SPINLOCK_INIT
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
atomic_shared_ptr() BOOST_SP_NOEXCEPT
|
||||
{
|
||||
boost::detail::spinlock init = BOOST_DETAIL_SPINLOCK_INIT;
|
||||
std::memcpy( &l_, &init, sizeof( init ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
atomic_shared_ptr( shared_ptr<T> p ) BOOST_SP_NOEXCEPT
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
: p_( std::move( p ) )
|
||||
|
@ -216,6 +216,8 @@ import testing ;
|
||||
[ run sp_constexpr_test.cpp ]
|
||||
[ run sp_constexpr_test2.cpp ]
|
||||
|
||||
[ run atomic_sp_constexpr_test.cpp ]
|
||||
|
||||
[ run local_sp_test.cpp ]
|
||||
[ run lsp_array_test.cpp ]
|
||||
[ run lsp_array_n_test.cpp ]
|
||||
|
67
test/atomic_sp_constexpr_test.cpp
Normal file
67
test/atomic_sp_constexpr_test.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// atomic_sp_constexpr_test.cpp
|
||||
//
|
||||
// Copyright 2017 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
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#define HAVE_CONSTEXPR_INIT
|
||||
|
||||
#if defined( BOOST_NO_CXX11_CONSTEXPR )
|
||||
# undef HAVE_CONSTEXPR_INIT
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
|
||||
# undef HAVE_CONSTEXPR_INIT
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR )
|
||||
# undef HAVE_CONSTEXPR_INIT
|
||||
#endif
|
||||
|
||||
#if !defined( HAVE_CONSTEXPR_INIT ) || !defined( BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX )
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/atomic_shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
Z();
|
||||
};
|
||||
|
||||
static Z z;
|
||||
|
||||
static boost::atomic_shared_ptr<X> p1;
|
||||
|
||||
Z::Z()
|
||||
{
|
||||
p1 = boost::shared_ptr<X>( new X );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
bost::shared_ptr<X> p2 = p1;
|
||||
|
||||
BOOST_TEST( p2.get() != 0 );
|
||||
BOOST_TEST_EQ( p2.use_count(), 1 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined( BOOST_NO_CXX11_CONSEXPR )
|
Reference in New Issue
Block a user