forked from boostorg/smart_ptr
Make default constructors constexpr
This commit is contained in:
@ -54,7 +54,7 @@ namespace boost
|
||||
namespace movelib
|
||||
{
|
||||
|
||||
template< class T, class D > class unique_ptr;
|
||||
template< class T, class D > class unique_ptr;
|
||||
|
||||
} // namespace movelib
|
||||
|
||||
@ -118,7 +118,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
shared_count(): pi_(0) // nothrow
|
||||
BOOST_CONSTEXPR shared_count(): pi_(0) // nothrow
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
@ -517,7 +517,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
weak_count(): pi_(0) // nothrow
|
||||
BOOST_CONSTEXPR weak_count(): pi_(0) // nothrow
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(weak_count_id)
|
||||
#endif
|
||||
|
@ -26,11 +26,11 @@ template<class T> class enable_shared_from_this
|
||||
{
|
||||
protected:
|
||||
|
||||
enable_shared_from_this() BOOST_SP_NOEXCEPT
|
||||
BOOST_CONSTEXPR enable_shared_from_this() BOOST_SP_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
enable_shared_from_this(enable_shared_from_this const &) BOOST_SP_NOEXCEPT
|
||||
BOOST_CONSTEXPR enable_shared_from_this(enable_shared_from_this const &) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -345,13 +345,13 @@ public:
|
||||
|
||||
typedef typename boost::detail::sp_element< T >::type element_type;
|
||||
|
||||
shared_ptr() BOOST_SP_NOEXCEPT : px( 0 ), pn()
|
||||
BOOST_CONSTEXPR shared_ptr() BOOST_SP_NOEXCEPT : px( 0 ), pn()
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
shared_ptr( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn()
|
||||
BOOST_CONSTEXPR shared_ptr( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
|
||||
typedef typename boost::detail::sp_element< T >::type element_type;
|
||||
|
||||
weak_ptr() BOOST_SP_NOEXCEPT : px(0), pn()
|
||||
BOOST_CONSTEXPR weak_ptr() BOOST_SP_NOEXCEPT : px(0), pn()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -213,6 +213,9 @@ import testing ;
|
||||
|
||||
[ run atomic_sp_test.cpp ]
|
||||
|
||||
[ run sp_constexpr_test.cpp ]
|
||||
[ run sp_constexpr_test2.cpp ]
|
||||
|
||||
[ run local_sp_test.cpp ]
|
||||
[ run lsp_array_test.cpp ]
|
||||
[ run lsp_array_n_test.cpp ]
|
||||
|
71
test/sp_constexpr_test.cpp
Normal file
71
test/sp_constexpr_test.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
//
|
||||
// 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>
|
||||
|
||||
#if defined( BOOST_NO_CXX11_CONSTEXPR )
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct X: public boost::enable_shared_from_this<X>
|
||||
{
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
Z();
|
||||
};
|
||||
|
||||
static Z z;
|
||||
|
||||
static boost::shared_ptr<X> p1;
|
||||
static boost::weak_ptr<X> p2;
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
static boost::shared_ptr<X> p3( nullptr );
|
||||
#endif
|
||||
|
||||
Z::Z()
|
||||
{
|
||||
p1.reset( new X );
|
||||
p2 = p1;
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
p3.reset( new X );
|
||||
#endif
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( p1.get() != 0 );
|
||||
BOOST_TEST_EQ( p1.use_count(), 1 );
|
||||
|
||||
BOOST_TEST_EQ( p2.use_count(), 1 );
|
||||
BOOST_TEST_EQ( p2.lock(), p1 );
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
BOOST_TEST( p3.get() != 0 );
|
||||
BOOST_TEST_EQ( p3.use_count(), 1 );
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined( BOOST_NO_CXX11_CONSEXPR )
|
53
test/sp_constexpr_test2.cpp
Normal file
53
test/sp_constexpr_test2.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// sp_constexpr_test2.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>
|
||||
|
||||
#if defined( BOOST_NO_CXX11_CONSTEXPR )
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct X: public boost::enable_shared_from_this<X>
|
||||
{
|
||||
int v_;
|
||||
|
||||
constexpr X() BOOST_NOEXCEPT: v_( 1 )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
Z();
|
||||
};
|
||||
|
||||
static Z z;
|
||||
static X x;
|
||||
|
||||
Z::Z()
|
||||
{
|
||||
BOOST_TEST_EQ( x.v_, 1 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined( BOOST_NO_CXX11_CONSEXPR )
|
Reference in New Issue
Block a user