forked from boostorg/smart_ptr
Compare commits
9 Commits
feature/gh
...
feature/dr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c808ca7ac8 | ||
|
|
a4e0508ab7 | ||
|
|
1dcc441ca1 | ||
|
|
cdf118b15b | ||
|
|
ab75e1f892 | ||
|
|
dcfb560de3 | ||
|
|
362fb1d677 | ||
|
|
79dac0e691 | ||
|
|
d08d035bdf |
@@ -34,7 +34,6 @@ local linux_pipeline(name, image, environment, packages = "", sources = [], arch
|
||||
'set -e',
|
||||
'uname -a',
|
||||
'echo $DRONE_STAGE_MACHINE',
|
||||
'wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -',
|
||||
] +
|
||||
(if sources != [] then [ ('apt-add-repository "' + source + '"') for source in sources ] else []) +
|
||||
(if packages != "" then [ 'apt-get update', 'apt-get -y install ' + packages ] else []) +
|
||||
@@ -340,40 +339,40 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 17 UBSAN",
|
||||
"Linux 24.04 Clang 17",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-17",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 17 ASAN",
|
||||
"Linux 24.04 Clang 18",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-17",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 ASAN",
|
||||
"Linux 24.04 Clang 19",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.10 Clang 19",
|
||||
"cppalliance/droneubuntu2410:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-19",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + ubsan,
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 20 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '11,14,17,20,23,2c' } + asan,
|
||||
"clang-20",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + ubsan,
|
||||
|
||||
19
.github/workflows/ci.yml
vendored
19
.github/workflows/ci.yml
vendored
@@ -276,14 +276,6 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: msvc-14.0
|
||||
cxxstd: 14,latest
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.2
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.3
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
@@ -295,7 +287,7 @@ jobs:
|
||||
- toolset: gcc
|
||||
cxxstd: "11,14,17,2a"
|
||||
addrmd: 64
|
||||
os: windows-2019
|
||||
os: windows-2022
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -497,8 +489,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
- os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -546,8 +537,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
- os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -613,8 +603,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-2019
|
||||
- os: windows-2022
|
||||
- os: windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
|
||||
28
appveyor.yml
28
appveyor.yml
@@ -21,6 +21,22 @@ environment:
|
||||
TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
CXXSTD: 14
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
CXXSTD: 17
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
CXXSTD: 20
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
CXXSTD: latest
|
||||
ADDRMD: 32,64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: clang-win
|
||||
CXXSTD: 14,17,latest
|
||||
@@ -33,14 +49,14 @@ environment:
|
||||
ADDPATH: C:\cygwin64\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 11,14,1z
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\mingw\bin;
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
ADDPATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 11,14,1z
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
ADDPATH: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;
|
||||
CXXSTD: 11,14,17
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
ADDPATH: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;
|
||||
TOOLSET: gcc
|
||||
CXXSTD: 11,14,1z
|
||||
CXXSTD: 11,14,17
|
||||
|
||||
install:
|
||||
- set BOOST_BRANCH=develop
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("The macro BOOST_SP_ENABLE_DEBUG_HOOKS has been deprecated in 1.87 and support for it will be removed.")
|
||||
BOOST_PRAGMA_MESSAGE("The macro BOOST_SP_ENABLE_DEBUG_HOOKS has been deprecated in 1.87 and support for it was removed in 1.90.")
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -55,13 +55,6 @@ template< class T, class D > class unique_ptr;
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
|
||||
int const shared_count_id = 0x2C35F101;
|
||||
int const weak_count_id = 0x298C38A4;
|
||||
|
||||
#endif
|
||||
|
||||
struct sp_nothrow_tag {};
|
||||
|
||||
template< class D > struct sp_inplace_tag
|
||||
@@ -112,32 +105,19 @@ private:
|
||||
|
||||
sp_counted_base * pi_;
|
||||
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
int id_;
|
||||
#endif
|
||||
|
||||
friend class weak_count;
|
||||
|
||||
public:
|
||||
|
||||
constexpr shared_count() noexcept: pi_(0)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
constexpr explicit shared_count( sp_counted_base * pi ) noexcept: pi_( pi )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
template<class Y> explicit shared_count( Y * p ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
|
||||
@@ -165,9 +145,6 @@ public:
|
||||
}
|
||||
|
||||
template<class P, class D> shared_count( P p, D d ): pi_(0)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
|
||||
@@ -195,9 +172,6 @@ public:
|
||||
}
|
||||
|
||||
template< class P, class D > shared_count( P p, sp_inplace_tag<D> ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
|
||||
@@ -225,9 +199,6 @@ public:
|
||||
}
|
||||
|
||||
template<class P, class D, class A> shared_count( P p, D d, A a ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
typedef sp_counted_impl_pda<P, D, A> impl_type;
|
||||
|
||||
@@ -272,9 +243,6 @@ public:
|
||||
}
|
||||
|
||||
template< class P, class D, class A > shared_count( P p, sp_inplace_tag< D >, A a ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
typedef sp_counted_impl_pda< P, D, A > impl_type;
|
||||
|
||||
@@ -324,9 +292,6 @@ public:
|
||||
|
||||
template<class Y>
|
||||
explicit shared_count( std::auto_ptr<Y> & r ): pi_( new sp_counted_impl_p<Y>( r.get() ) )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
#ifdef BOOST_NO_EXCEPTIONS
|
||||
|
||||
@@ -344,9 +309,6 @@ public:
|
||||
|
||||
template<class Y, class D>
|
||||
explicit shared_count( std::unique_ptr<Y, D> & r ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
typedef typename sp_convert_reference<D>::type D2;
|
||||
|
||||
@@ -367,9 +329,6 @@ public:
|
||||
|
||||
template<class Y, class D>
|
||||
explicit shared_count( boost::movelib::unique_ptr<Y, D> & r ): pi_( 0 )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
typedef typename sp_convert_reference<D>::type D2;
|
||||
|
||||
@@ -391,23 +350,14 @@ public:
|
||||
~shared_count() /*noexcept*/
|
||||
{
|
||||
if( pi_ != 0 ) pi_->release();
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
id_ = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
shared_count(shared_count const & r) noexcept: pi_(r.pi_)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
if( pi_ != 0 ) pi_->add_ref_copy();
|
||||
}
|
||||
|
||||
shared_count(shared_count && r) noexcept: pi_(r.pi_)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
r.pi_ = 0;
|
||||
}
|
||||
@@ -493,33 +443,20 @@ private:
|
||||
|
||||
sp_counted_base * pi_;
|
||||
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
int id_;
|
||||
#endif
|
||||
|
||||
friend class shared_count;
|
||||
|
||||
public:
|
||||
|
||||
constexpr weak_count() noexcept: pi_(0)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(weak_count_id)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
weak_count(shared_count const & r) noexcept: pi_(r.pi_)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(weak_count_id)
|
||||
#endif
|
||||
{
|
||||
if(pi_ != 0) pi_->weak_add_ref();
|
||||
}
|
||||
|
||||
weak_count(weak_count const & r) noexcept: pi_(r.pi_)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(weak_count_id)
|
||||
#endif
|
||||
{
|
||||
if(pi_ != 0) pi_->weak_add_ref();
|
||||
}
|
||||
@@ -527,9 +464,6 @@ public:
|
||||
// Move support
|
||||
|
||||
weak_count(weak_count && r) noexcept: pi_(r.pi_)
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(weak_count_id)
|
||||
#endif
|
||||
{
|
||||
r.pi_ = 0;
|
||||
}
|
||||
@@ -537,9 +471,6 @@ public:
|
||||
~weak_count() /*noexcept*/
|
||||
{
|
||||
if(pi_ != 0) pi_->weak_release();
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
id_ = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
weak_count & operator= (shared_count const & r) noexcept
|
||||
@@ -614,9 +545,6 @@ public:
|
||||
};
|
||||
|
||||
inline shared_count::shared_count( weak_count const & r ): pi_( r.pi_ )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
if( pi_ == 0 || !pi_->add_ref_lock() )
|
||||
{
|
||||
@@ -625,9 +553,6 @@ inline shared_count::shared_count( weak_count const & r ): pi_( r.pi_ )
|
||||
}
|
||||
|
||||
inline shared_count::shared_count( weak_count const & r, sp_nothrow_tag ) noexcept: pi_( r.pi_ )
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
, id_(shared_count_id)
|
||||
#endif
|
||||
{
|
||||
if( pi_ != 0 && !pi_->add_ref_lock() )
|
||||
{
|
||||
|
||||
@@ -38,13 +38,6 @@
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
|
||||
void sp_scalar_constructor_hook( void * px, std::size_t size, void * pn );
|
||||
void sp_scalar_destructor_hook( void * px, std::size_t size, void * pn );
|
||||
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
@@ -76,16 +69,10 @@ public:
|
||||
|
||||
explicit sp_counted_impl_p( X * px ): px_( px )
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_scalar_constructor_hook( px, sizeof(X), this );
|
||||
#endif
|
||||
}
|
||||
|
||||
void dispose() noexcept override
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_scalar_destructor_hook( px_, sizeof(X), this );
|
||||
#endif
|
||||
boost::checked_delete( px_ );
|
||||
}
|
||||
|
||||
|
||||
37
include/boost/smart_ptr/detail/sp_cxx20_constexpr.hpp
Normal file
37
include/boost/smart_ptr/detail/sp_cxx20_constexpr.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_SP_CXX20_CONSTEXPR_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_DETAIL_SP_CXX20_CONSTEXPR_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// detail/sp_noexcept.hpp
|
||||
//
|
||||
// Copyright 2025 Mathias Stearn
|
||||
//
|
||||
// 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
|
||||
|
||||
|
||||
// This macro is used to mark functions as constexpr if the compiler supports
|
||||
// constexpr destructors. Since you can't have a constexpr smart pointer object,
|
||||
// everything except null constructors are guided behind this macro. Because
|
||||
// this also guards a use of dynamic_cast, we need to check for its availability
|
||||
// as well. It isn't worth splitting out since all known compilers that support
|
||||
// constexpr dynamic_cast also support constexpr destructors.
|
||||
//
|
||||
// WARNING: This does not check for changing active member of a union in
|
||||
// constant expressions which is allowed in C++20. If that is needed, we
|
||||
// need to raise the checked version to 202002L.
|
||||
#if defined(__cpp_constexpr_dynamic_alloc) && __cpp_constexpr_dynamic_alloc >= 201907L \
|
||||
&& defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||
#define BOOST_SP_CXX20_CONSTEXPR constexpr
|
||||
#else
|
||||
#define BOOST_SP_CXX20_CONSTEXPR
|
||||
#define BOOST_SP_NO_CXX20_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_CXX20_CONSTEXPR_HPP_INCLUDED
|
||||
@@ -13,6 +13,7 @@
|
||||
// See http://www.boost.org/libs/smart_ptr/ for documentation.
|
||||
//
|
||||
|
||||
#include <boost/smart_ptr/detail/sp_cxx20_constexpr.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_convertible.hpp>
|
||||
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
@@ -53,29 +54,29 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
intrusive_ptr( T * p, bool add_ref = true ): px( p )
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr( T * p, bool add_ref = true ): px( p )
|
||||
{
|
||||
if( px != 0 && add_ref ) intrusive_ptr_add_ref( px );
|
||||
}
|
||||
|
||||
template<class U>
|
||||
intrusive_ptr( intrusive_ptr<U> const & rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty() )
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr( intrusive_ptr<U> const & rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty() )
|
||||
: px( rhs.get() )
|
||||
{
|
||||
if( px != 0 ) intrusive_ptr_add_ref( px );
|
||||
}
|
||||
|
||||
intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px )
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px )
|
||||
{
|
||||
if( px != 0 ) intrusive_ptr_add_ref( px );
|
||||
}
|
||||
|
||||
~intrusive_ptr()
|
||||
BOOST_SP_CXX20_CONSTEXPR ~intrusive_ptr()
|
||||
{
|
||||
if( px != 0 ) intrusive_ptr_release( px );
|
||||
}
|
||||
|
||||
template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs)
|
||||
template<class U> BOOST_SP_CXX20_CONSTEXPR intrusive_ptr & operator=(intrusive_ptr<U> const & rhs)
|
||||
{
|
||||
this_type(rhs).swap(*this);
|
||||
return *this;
|
||||
@@ -83,12 +84,12 @@ public:
|
||||
|
||||
// Move support
|
||||
|
||||
intrusive_ptr(intrusive_ptr && rhs) noexcept : px( rhs.px )
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr(intrusive_ptr && rhs) noexcept : px( rhs.px )
|
||||
{
|
||||
rhs.px = 0;
|
||||
}
|
||||
|
||||
intrusive_ptr & operator=(intrusive_ptr && rhs) noexcept
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr & operator=(intrusive_ptr && rhs) noexcept
|
||||
{
|
||||
this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this);
|
||||
return *this;
|
||||
@@ -97,76 +98,76 @@ public:
|
||||
template<class U> friend class intrusive_ptr;
|
||||
|
||||
template<class U>
|
||||
intrusive_ptr(intrusive_ptr<U> && rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty())
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr(intrusive_ptr<U> && rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty())
|
||||
: px( rhs.px )
|
||||
{
|
||||
rhs.px = 0;
|
||||
}
|
||||
|
||||
template<class U>
|
||||
intrusive_ptr & operator=(intrusive_ptr<U> && rhs) noexcept
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr & operator=(intrusive_ptr<U> && rhs) noexcept
|
||||
{
|
||||
this_type( static_cast< intrusive_ptr<U> && >( rhs ) ).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
intrusive_ptr & operator=(intrusive_ptr const & rhs)
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr & operator=(intrusive_ptr const & rhs)
|
||||
{
|
||||
this_type(rhs).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
intrusive_ptr & operator=(T * rhs)
|
||||
BOOST_SP_CXX20_CONSTEXPR intrusive_ptr & operator=(T * rhs)
|
||||
{
|
||||
this_type(rhs).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset()
|
||||
BOOST_SP_CXX20_CONSTEXPR void reset()
|
||||
{
|
||||
this_type().swap( *this );
|
||||
}
|
||||
|
||||
void reset( T * rhs )
|
||||
BOOST_SP_CXX20_CONSTEXPR void reset( T * rhs )
|
||||
{
|
||||
this_type( rhs ).swap( *this );
|
||||
}
|
||||
|
||||
void reset( T * rhs, bool add_ref )
|
||||
BOOST_SP_CXX20_CONSTEXPR void reset( T * rhs, bool add_ref )
|
||||
{
|
||||
this_type( rhs, add_ref ).swap( *this );
|
||||
}
|
||||
|
||||
T * get() const noexcept
|
||||
BOOST_SP_CXX20_CONSTEXPR T * get() const noexcept
|
||||
{
|
||||
return px;
|
||||
}
|
||||
|
||||
T * detach() noexcept
|
||||
BOOST_SP_CXX20_CONSTEXPR T * detach() noexcept
|
||||
{
|
||||
T * ret = px;
|
||||
px = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
T & operator*() const BOOST_SP_NOEXCEPT_WITH_ASSERT
|
||||
BOOST_SP_CXX20_CONSTEXPR T & operator*() const BOOST_SP_NOEXCEPT_WITH_ASSERT
|
||||
{
|
||||
BOOST_ASSERT( px != 0 );
|
||||
return *px;
|
||||
}
|
||||
|
||||
T * operator->() const BOOST_SP_NOEXCEPT_WITH_ASSERT
|
||||
BOOST_SP_CXX20_CONSTEXPR T * operator->() const BOOST_SP_NOEXCEPT_WITH_ASSERT
|
||||
{
|
||||
BOOST_ASSERT( px != 0 );
|
||||
return px;
|
||||
}
|
||||
|
||||
explicit operator bool () const noexcept
|
||||
BOOST_SP_CXX20_CONSTEXPR explicit operator bool () const noexcept
|
||||
{
|
||||
return px != 0;
|
||||
}
|
||||
|
||||
void swap(intrusive_ptr & rhs) noexcept
|
||||
BOOST_SP_CXX20_CONSTEXPR void swap(intrusive_ptr & rhs) noexcept
|
||||
{
|
||||
T * tmp = px;
|
||||
px = rhs.px;
|
||||
@@ -178,101 +179,101 @@ private:
|
||||
T * px;
|
||||
};
|
||||
|
||||
template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) noexcept
|
||||
{
|
||||
return a.get() == b.get();
|
||||
}
|
||||
|
||||
template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) noexcept
|
||||
{
|
||||
return a.get() != b.get();
|
||||
}
|
||||
|
||||
template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline bool operator==(intrusive_ptr<T> const & a, U * b) noexcept
|
||||
{
|
||||
return a.get() == b;
|
||||
}
|
||||
|
||||
template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline bool operator!=(intrusive_ptr<T> const & a, U * b) noexcept
|
||||
{
|
||||
return a.get() != b;
|
||||
}
|
||||
|
||||
template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline bool operator==(T * a, intrusive_ptr<U> const & b) noexcept
|
||||
{
|
||||
return a == b.get();
|
||||
}
|
||||
|
||||
template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline bool operator!=(T * a, intrusive_ptr<U> const & b) noexcept
|
||||
{
|
||||
return a != b.get();
|
||||
}
|
||||
|
||||
template<class T> inline bool operator==( intrusive_ptr<T> const & p, std::nullptr_t ) noexcept
|
||||
template<class T> BOOST_SP_CXX20_CONSTEXPR inline bool operator==( intrusive_ptr<T> const & p, std::nullptr_t ) noexcept
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator==( std::nullptr_t, intrusive_ptr<T> const & p ) noexcept
|
||||
template<class T> BOOST_SP_CXX20_CONSTEXPR inline bool operator==( std::nullptr_t, intrusive_ptr<T> const & p ) noexcept
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( intrusive_ptr<T> const & p, std::nullptr_t ) noexcept
|
||||
template<class T> BOOST_SP_CXX20_CONSTEXPR inline bool operator!=( intrusive_ptr<T> const & p, std::nullptr_t ) noexcept
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( std::nullptr_t, intrusive_ptr<T> const & p ) noexcept
|
||||
template<class T> BOOST_SP_CXX20_CONSTEXPR inline bool operator!=( std::nullptr_t, intrusive_ptr<T> const & p ) noexcept
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b) noexcept
|
||||
template<class T> BOOST_SP_CXX20_CONSTEXPR inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b) noexcept
|
||||
{
|
||||
return std::less<T *>()(a.get(), b.get());
|
||||
}
|
||||
|
||||
template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs) noexcept
|
||||
template<class T> BOOST_SP_CXX20_CONSTEXPR inline void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs) noexcept
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
// mem_fn support
|
||||
|
||||
template<class T> T * get_pointer(intrusive_ptr<T> const & p) noexcept
|
||||
template<class T> BOOST_SP_CXX20_CONSTEXPR inline T * get_pointer(intrusive_ptr<T> const & p) noexcept
|
||||
{
|
||||
return p.get();
|
||||
}
|
||||
|
||||
// pointer casts
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
|
||||
{
|
||||
return static_cast<T *>(p.get());
|
||||
}
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
|
||||
{
|
||||
return const_cast<T *>(p.get());
|
||||
}
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
|
||||
{
|
||||
return dynamic_cast<T *>(p.get());
|
||||
}
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> static_pointer_cast( intrusive_ptr<U> && p ) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline intrusive_ptr<T> static_pointer_cast( intrusive_ptr<U> && p ) noexcept
|
||||
{
|
||||
return intrusive_ptr<T>( static_cast<T*>( p.detach() ), false );
|
||||
}
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> const_pointer_cast( intrusive_ptr<U> && p ) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline intrusive_ptr<T> const_pointer_cast( intrusive_ptr<U> && p ) noexcept
|
||||
{
|
||||
return intrusive_ptr<T>( const_cast<T*>( p.detach() ), false );
|
||||
}
|
||||
|
||||
template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast( intrusive_ptr<U> && p ) noexcept
|
||||
template<class T, class U> BOOST_SP_CXX20_CONSTEXPR inline intrusive_ptr<T> dynamic_pointer_cast( intrusive_ptr<U> && p ) noexcept
|
||||
{
|
||||
T * p2 = dynamic_cast<T*>( p.get() );
|
||||
|
||||
|
||||
@@ -22,15 +22,6 @@
|
||||
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.
|
||||
@@ -55,16 +46,10 @@ public:
|
||||
|
||||
explicit scoped_array( T * p = 0 ) noexcept : px( p )
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_array_constructor_hook( px );
|
||||
#endif
|
||||
}
|
||||
|
||||
~scoped_array() noexcept
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_array_destructor_hook( px );
|
||||
#endif
|
||||
boost::checked_array_delete( px );
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,6 @@
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// Debug hooks
|
||||
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
|
||||
void sp_scalar_constructor_hook(void * p);
|
||||
void sp_scalar_destructor_hook(void * p);
|
||||
|
||||
#endif
|
||||
|
||||
// scoped_ptr mimics a built-in pointer except that it guarantees deletion
|
||||
// of the object pointed to, either on destruction of the scoped_ptr or via
|
||||
// an explicit reset(). scoped_ptr is a simple solution for simple needs;
|
||||
@@ -65,27 +56,18 @@ public:
|
||||
|
||||
explicit scoped_ptr( T * p = 0 ) noexcept : px( p )
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_scalar_constructor_hook( px );
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_AUTO_PTR
|
||||
|
||||
explicit scoped_ptr( std::auto_ptr<T> p ) noexcept : px( p.release() )
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_scalar_constructor_hook( px );
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
~scoped_ptr() noexcept
|
||||
{
|
||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||
boost::sp_scalar_destructor_hook( px );
|
||||
#endif
|
||||
boost::checked_delete( px );
|
||||
}
|
||||
|
||||
|
||||
@@ -245,6 +245,7 @@ run atomic_sp_test.cpp ;
|
||||
|
||||
run sp_constexpr_test.cpp ;
|
||||
run sp_constexpr_test2.cpp ;
|
||||
compile ip_constexpr_test.cpp ;
|
||||
|
||||
run atomic_sp_constexpr_test.cpp ;
|
||||
|
||||
|
||||
133
test/ip_constexpr_test.cpp
Normal file
133
test/ip_constexpr_test.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// ip_constexpr_test.cpp
|
||||
//
|
||||
// Copyright 2025 Mathias Stearn
|
||||
//
|
||||
// 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/intrusive_ptr.hpp>
|
||||
|
||||
#ifndef BOOST_SP_NO_CXX20_CONSTEXPR
|
||||
|
||||
struct dummy {
|
||||
// no-ops, so safe on pointers to static constexpr variables
|
||||
friend constexpr void intrusive_ptr_add_ref(const dummy *) {}
|
||||
friend constexpr void intrusive_ptr_release(const dummy *) {}
|
||||
};
|
||||
static constexpr dummy d;
|
||||
|
||||
struct subdummy : dummy {};
|
||||
|
||||
// Test that basic operations work at compile time.
|
||||
static_assert(bool(boost::intrusive_ptr<const dummy>(&d)));
|
||||
static_assert(!bool(boost::intrusive_ptr<dummy>(nullptr)));
|
||||
static_assert(!bool(boost::intrusive_ptr<dummy>()));
|
||||
static_assert(!bool(boost::intrusive_ptr<dummy>(boost::intrusive_ptr<subdummy>())));
|
||||
static_assert(&*boost::intrusive_ptr<const dummy>(&d) == &d);
|
||||
static_assert(boost::intrusive_ptr<const dummy>(&d).operator->() == &d);
|
||||
static_assert(boost::intrusive_ptr<dummy>() == nullptr);
|
||||
static_assert(boost::intrusive_ptr<dummy>() == boost::intrusive_ptr<dummy>(nullptr));
|
||||
static_assert(boost::intrusive_ptr<dummy>() != boost::intrusive_ptr<const dummy>(&d));
|
||||
static_assert(boost::intrusive_ptr<const dummy>(&d) != nullptr);
|
||||
static_assert(boost::intrusive_ptr<const dummy>(&d) == boost::intrusive_ptr<const dummy>(&d));
|
||||
static_assert(boost::intrusive_ptr<const dummy>(&d) == boost::intrusive_ptr<const dummy>(&d).get());
|
||||
static_assert(boost::intrusive_ptr<const dummy>(&d) == boost::intrusive_ptr<const dummy>(&d).detach());
|
||||
static_assert(!(boost::intrusive_ptr<const dummy>(&d) < boost::intrusive_ptr<const dummy>(&d)));
|
||||
static_assert(boost::get_pointer(boost::intrusive_ptr<const dummy>(&d)) == &d);
|
||||
static_assert(boost::static_pointer_cast<const dummy>( boost::intrusive_ptr<const dummy>(&d)) == &d);
|
||||
static_assert(boost::const_pointer_cast<const dummy>( boost::intrusive_ptr<const dummy>(&d)) == &d);
|
||||
static_assert(boost::dynamic_pointer_cast<const dummy>( boost::intrusive_ptr<const dummy>(&d)) == &d);
|
||||
|
||||
constexpr auto lvalue = boost::intrusive_ptr<const dummy>(&d);
|
||||
constexpr auto lvalue_convertible = boost::intrusive_ptr<const subdummy>();
|
||||
static_assert(boost::intrusive_ptr<const dummy>(lvalue) == &d);
|
||||
static_assert(!boost::intrusive_ptr<const dummy>(lvalue_convertible));
|
||||
static_assert(boost::static_pointer_cast<const dummy>(lvalue) == &d);
|
||||
static_assert(boost::const_pointer_cast<const dummy>(lvalue) == &d);
|
||||
static_assert(boost::dynamic_pointer_cast<const dummy>(lvalue) == &d);
|
||||
|
||||
// Works in places that static_assert doesn't, like expressions with
|
||||
// non-constexpr variables in constexpr functions.
|
||||
template <typename T> constexpr void semi_static_assert(T b) {
|
||||
if (!b)
|
||||
throw "assertion failed"; // Not constexpr so fails compile.
|
||||
}
|
||||
|
||||
constexpr bool test_swap() {
|
||||
auto p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
auto p2 = boost::intrusive_ptr<const dummy>();
|
||||
swap(p1, p2);
|
||||
semi_static_assert(!p1 && p2);
|
||||
p1.swap(p2);
|
||||
semi_static_assert(p1 && !p2);
|
||||
return true;
|
||||
}
|
||||
static_assert(test_swap());
|
||||
|
||||
constexpr bool test_reset_assign() {
|
||||
// Test assignments resulting in nullptr
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
p1.reset();
|
||||
semi_static_assert(!p1);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
p1.reset(nullptr);
|
||||
semi_static_assert(!p1);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
p1 = nullptr;
|
||||
semi_static_assert(!p1);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
p1 = boost::intrusive_ptr<const dummy>();
|
||||
semi_static_assert(!p1);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
p1 = boost::intrusive_ptr<subdummy>();
|
||||
semi_static_assert(!p1);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
p1 = lvalue_convertible;
|
||||
semi_static_assert(!p1);
|
||||
}
|
||||
|
||||
// Test assignments resulting in &d
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>();
|
||||
p1.reset(&d);
|
||||
semi_static_assert(p1 == &d);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>();
|
||||
p1.reset(&d, true);
|
||||
semi_static_assert(p1 == &d);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>();
|
||||
p1 = boost::intrusive_ptr<const dummy>(&d);
|
||||
semi_static_assert(p1 == &d);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>();
|
||||
p1 = lvalue;
|
||||
semi_static_assert(p1 == &d);
|
||||
}
|
||||
{
|
||||
auto p1 = boost::intrusive_ptr<const dummy>();
|
||||
p1 = &d;
|
||||
semi_static_assert(p1 == &d);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static_assert(test_reset_assign());
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user