mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
offset_ptr improvements:
- Use simplier traits to reduce dependencies and add support for nullptr - Add tests cover construction/assignment from literal zero and nullptr
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
#include <boost/interprocess/offset_ptr.hpp>
|
||||
#include <boost/interprocess/detail/type_traits.hpp>
|
||||
#include <boost/intrusive/pointer_traits.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
using namespace boost::interprocess;
|
||||
@@ -34,15 +33,15 @@ void test_types_and_conversions()
|
||||
typedef offset_ptr<volatile int> pvint_t;
|
||||
typedef offset_ptr<const volatile int> pcvint_t;
|
||||
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pint_t::element_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pcint_t::element_type, const int>::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pvint_t::element_type, volatile int>::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pcvint_t::element_type, const volatile int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pint_t::element_type, int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pcint_t::element_type, const int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pvint_t::element_type, volatile int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pcvint_t::element_type, const volatile int>::value));
|
||||
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pint_t::value_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pcint_t::value_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pvint_t::value_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<pcvint_t::value_type, int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pint_t::value_type, int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pcint_t::value_type, int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pvint_t::value_type, int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<pcvint_t::value_type, int>::value));
|
||||
int dummy_int = 9;
|
||||
|
||||
{ pint_t pint(&dummy_int);
|
||||
@@ -71,6 +70,39 @@ void test_types_and_conversions()
|
||||
pvint_t pvint(0);
|
||||
pcvint_t pcvint(0);
|
||||
|
||||
{
|
||||
pint_t pint2 = 0;
|
||||
pcint_t pcint2 = 0;
|
||||
pvint_t pvint2 = 0;
|
||||
pcvint_t pcvint2 = 0;
|
||||
(void)pint2;
|
||||
(void)pcint2;
|
||||
(void)pvint2;
|
||||
(void)pcvint2;
|
||||
}
|
||||
|
||||
{
|
||||
pint_t pint2 = op_nullptr_t();
|
||||
pcint_t pcint2 = op_nullptr_t();
|
||||
pvint_t pvint2 = op_nullptr_t();
|
||||
pcvint_t pcvint2 = op_nullptr_t();
|
||||
(void)pint2;
|
||||
(void)pcint2;
|
||||
(void)pvint2;
|
||||
(void)pcvint2;
|
||||
}
|
||||
|
||||
{
|
||||
pint_t pint2((op_nullptr_t()));
|
||||
pcint_t pcint2((op_nullptr_t()));
|
||||
pvint_t pvint2((op_nullptr_t()));
|
||||
pcvint_t pcvint2((op_nullptr_t()));
|
||||
(void)pint2;
|
||||
(void)pcint2;
|
||||
(void)pvint2;
|
||||
(void)pcvint2;
|
||||
}
|
||||
|
||||
pint = &dummy_int;
|
||||
pcint = &dummy_int;
|
||||
pvint = &dummy_int;
|
||||
@@ -108,6 +140,47 @@ void test_types_and_conversions()
|
||||
|
||||
BOOST_TEST( (pcint - pint) == 0);
|
||||
BOOST_TEST( (pint - pcint) == 0);
|
||||
|
||||
typedef offset_ptr<void> pvoid_t;
|
||||
typedef offset_ptr<const void> pcvoid_t;
|
||||
typedef offset_ptr<volatile void> pvvoid_t;
|
||||
typedef offset_ptr<const volatile void> pcvvoid_t;
|
||||
{
|
||||
pvoid_t pvoid = pint;
|
||||
pcvoid_t pcvoid = pcint;
|
||||
pvvoid_t pvvoid = pvint;
|
||||
pcvvoid_t pcvvoid = pcvint;
|
||||
(void)pvoid;
|
||||
(void)pcvoid;
|
||||
(void)pvvoid;
|
||||
(void)pcvvoid;
|
||||
}
|
||||
{
|
||||
pvoid_t pvoid(pint);
|
||||
pcvoid_t pcvoid(pcint);
|
||||
pvvoid_t pvvoid(pvint);
|
||||
pcvvoid_t pcvvoid(pcvint);
|
||||
(void)pvoid;
|
||||
(void)pcvoid;
|
||||
(void)pvvoid;
|
||||
(void)pcvvoid;
|
||||
}
|
||||
{
|
||||
pvoid_t pvoid;
|
||||
pcvoid_t pcvoid;
|
||||
pvvoid_t pvvoid;
|
||||
pcvvoid_t pcvvoid;
|
||||
|
||||
pvoid = pint;
|
||||
pcvoid = pcint;
|
||||
pvvoid = pvint;
|
||||
pcvvoid = pcvint;
|
||||
|
||||
(void)pvoid;
|
||||
(void)pcvoid;
|
||||
(void)pvvoid;
|
||||
(void)pcvvoid;
|
||||
}
|
||||
}
|
||||
|
||||
template<class BasePtr, class DerivedPtr>
|
||||
@@ -116,6 +189,8 @@ void test_base_derived_impl()
|
||||
typename DerivedPtr::element_type d;
|
||||
DerivedPtr pderi(&d);
|
||||
|
||||
{ BasePtr pbase2 = pderi; (void)pbase2; }
|
||||
|
||||
BasePtr pbase(pderi);
|
||||
pbase = pderi;
|
||||
BOOST_TEST(pbase == pderi);
|
||||
@@ -234,10 +309,10 @@ bool test_pointer_traits()
|
||||
{
|
||||
typedef offset_ptr<int> OInt;
|
||||
typedef boost::intrusive::pointer_traits< OInt > PTOInt;
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<PTOInt::element_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<PTOInt::pointer, OInt >::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<PTOInt::difference_type, OInt::difference_type >::value));
|
||||
BOOST_STATIC_ASSERT((ipcdetail::is_same<PTOInt::rebind_pointer<double>::type, offset_ptr<double> >::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<PTOInt::element_type, int>::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<PTOInt::pointer, OInt >::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<PTOInt::difference_type, OInt::difference_type >::value));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((ipcdetail::is_same<PTOInt::rebind_pointer<double>::type, offset_ptr<double> >::value));
|
||||
int dummy;
|
||||
OInt oi(&dummy);
|
||||
if(boost::intrusive::pointer_traits<OInt>::pointer_to(dummy) != oi){
|
||||
@@ -253,7 +328,7 @@ struct node
|
||||
|
||||
void test_pointer_plus_bits()
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::intrusive::max_pointer_plus_bits< offset_ptr<void>, boost::move_detail::alignment_of<node>::value >::value >= 1U));
|
||||
BOOST_INTERPROCESS_STATIC_ASSERT((boost::intrusive::max_pointer_plus_bits< offset_ptr<void>, boost::move_detail::alignment_of<node>::value >::value >= 1U));
|
||||
typedef boost::intrusive::pointer_plus_bits< offset_ptr<node>, 1u > ptr_plus_bits;
|
||||
|
||||
node n, n2;
|
||||
|
||||
Reference in New Issue
Block a user