forked from boostorg/smart_ptr
Implement allocate_local_shared for arrays
Also fix the local_shared_ptr constructor to use element_type
This commit is contained in:
240
include/boost/smart_ptr/allocate_local_shared_array.hpp
Normal file
240
include/boost/smart_ptr/allocate_local_shared_array.hpp
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef BOOST_SMART_PTR_ALLOCATE_LOCAL_SHARED_ARRAY_HPP
|
||||||
|
#define BOOST_SMART_PTR_ALLOCATE_LOCAL_SHARED_ARRAY_HPP
|
||||||
|
|
||||||
|
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||||
|
#include <boost/smart_ptr/local_shared_ptr.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<class>
|
||||||
|
struct lsp_if_array { };
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct lsp_if_array<T[]> {
|
||||||
|
typedef boost::local_shared_ptr<T[]> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class>
|
||||||
|
struct lsp_if_size_array { };
|
||||||
|
|
||||||
|
template<class T, std::size_t N>
|
||||||
|
struct lsp_if_size_array<T[N]> {
|
||||||
|
typedef boost::local_shared_ptr<T[N]> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
class lsp_array_base
|
||||||
|
: public local_counted_base {
|
||||||
|
public:
|
||||||
|
void set(sp_counted_base* base) BOOST_SP_NOEXCEPT {
|
||||||
|
shared_count(base).swap(count_);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT {
|
||||||
|
shared_count().swap(count_);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT {
|
||||||
|
return count_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
shared_count count_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class A>
|
||||||
|
class lsp_array_state
|
||||||
|
: public lsp_array_base {
|
||||||
|
public:
|
||||||
|
typedef A type;
|
||||||
|
|
||||||
|
lsp_array_state(const A& allocator, std::size_t size) BOOST_SP_NOEXCEPT
|
||||||
|
: allocator_(allocator),
|
||||||
|
size_(size) { }
|
||||||
|
|
||||||
|
A& allocator() BOOST_SP_NOEXCEPT {
|
||||||
|
return allocator_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t size() const BOOST_SP_NOEXCEPT {
|
||||||
|
return size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
A allocator_;
|
||||||
|
std::size_t size_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class A, std::size_t N>
|
||||||
|
class lsp_size_array_state
|
||||||
|
: public lsp_array_base {
|
||||||
|
public:
|
||||||
|
typedef A type;
|
||||||
|
|
||||||
|
lsp_size_array_state(const A& allocator, std::size_t) BOOST_SP_NOEXCEPT
|
||||||
|
: allocator_(allocator) { }
|
||||||
|
|
||||||
|
A& allocator() BOOST_SP_NOEXCEPT {
|
||||||
|
return allocator_;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CONSTEXPR std::size_t size() const BOOST_SP_NOEXCEPT {
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
A allocator_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* detail */
|
||||||
|
|
||||||
|
template<class T, class A>
|
||||||
|
inline typename detail::lsp_if_array<T>::type
|
||||||
|
allocate_local_shared(const A& allocator, std::size_t count)
|
||||||
|
{
|
||||||
|
typedef typename detail::sp_array_element<T>::type type;
|
||||||
|
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||||
|
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||||
|
typedef detail::lsp_array_state<other> state;
|
||||||
|
typedef detail::sp_array_base<state> base;
|
||||||
|
std::size_t size = count * detail::sp_array_count<type>::value;
|
||||||
|
detail::sp_array_result<other, base> result(allocator, size);
|
||||||
|
base* node = result.get();
|
||||||
|
::new(static_cast<void*>(node)) base(allocator, size);
|
||||||
|
detail::lsp_array_base& local = node->state();
|
||||||
|
local.set(node);
|
||||||
|
void* start = detail::sp_array_start<scalar>(node);
|
||||||
|
result.release();
|
||||||
|
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||||
|
static_cast<type*>(start), &local);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class A>
|
||||||
|
inline typename detail::lsp_if_size_array<T>::type
|
||||||
|
allocate_local_shared(const A& allocator)
|
||||||
|
{
|
||||||
|
typedef typename detail::sp_array_element<T>::type type;
|
||||||
|
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||||
|
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||||
|
enum {
|
||||||
|
size = detail::sp_array_count<T>::value
|
||||||
|
};
|
||||||
|
typedef detail::lsp_size_array_state<other, size> state;
|
||||||
|
typedef detail::sp_array_base<state> base;
|
||||||
|
detail::sp_array_result<other, base> result(allocator, size);
|
||||||
|
base* node = result.get();
|
||||||
|
::new(static_cast<void*>(node)) base(allocator, size);
|
||||||
|
detail::lsp_array_base& local = node->state();
|
||||||
|
local.set(node);
|
||||||
|
void* start = detail::sp_array_start<scalar>(node);
|
||||||
|
result.release();
|
||||||
|
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||||
|
static_cast<type*>(start), &local);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class A>
|
||||||
|
inline typename detail::lsp_if_array<T>::type
|
||||||
|
allocate_local_shared(const A& allocator, std::size_t count,
|
||||||
|
const typename detail::sp_array_element<T>::type& value)
|
||||||
|
{
|
||||||
|
typedef typename detail::sp_array_element<T>::type type;
|
||||||
|
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||||
|
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||||
|
typedef detail::lsp_array_state<other> state;
|
||||||
|
typedef detail::sp_array_base<state> base;
|
||||||
|
std::size_t size = count * detail::sp_array_count<type>::value;
|
||||||
|
detail::sp_array_result<other, base> result(allocator, size);
|
||||||
|
base* node = result.get();
|
||||||
|
::new(static_cast<void*>(node)) base(allocator, size,
|
||||||
|
reinterpret_cast<const scalar*>(&value),
|
||||||
|
detail::sp_array_count<type>::value);
|
||||||
|
detail::lsp_array_base& local = node->state();
|
||||||
|
local.set(node);
|
||||||
|
void* start = detail::sp_array_start<scalar>(node);
|
||||||
|
result.release();
|
||||||
|
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||||
|
static_cast<type*>(start), &local);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class A>
|
||||||
|
inline typename detail::lsp_if_size_array<T>::type
|
||||||
|
allocate_local_shared(const A& allocator,
|
||||||
|
const typename detail::sp_array_element<T>::type& value)
|
||||||
|
{
|
||||||
|
typedef typename detail::sp_array_element<T>::type type;
|
||||||
|
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||||
|
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||||
|
enum {
|
||||||
|
size = detail::sp_array_count<T>::value
|
||||||
|
};
|
||||||
|
typedef detail::lsp_size_array_state<other, size> state;
|
||||||
|
typedef detail::sp_array_base<state> base;
|
||||||
|
detail::sp_array_result<other, base> result(allocator, size);
|
||||||
|
base* node = result.get();
|
||||||
|
::new(static_cast<void*>(node)) base(allocator, size,
|
||||||
|
reinterpret_cast<const scalar*>(&value),
|
||||||
|
detail::sp_array_count<type>::value);
|
||||||
|
detail::lsp_array_base& local = node->state();
|
||||||
|
local.set(node);
|
||||||
|
void* start = detail::sp_array_start<scalar>(node);
|
||||||
|
result.release();
|
||||||
|
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||||
|
static_cast<type*>(start), &local);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class A>
|
||||||
|
inline typename detail::lsp_if_array<T>::type
|
||||||
|
allocate_local_shared_noinit(const A& allocator, std::size_t count)
|
||||||
|
{
|
||||||
|
typedef typename detail::sp_array_element<T>::type type;
|
||||||
|
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||||
|
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||||
|
typedef detail::lsp_array_state<other> state;
|
||||||
|
typedef detail::sp_array_base<state, false> base;
|
||||||
|
std::size_t size = count * detail::sp_array_count<type>::value;
|
||||||
|
detail::sp_array_result<other, base> result(allocator, size);
|
||||||
|
base* node = result.get();
|
||||||
|
::new(static_cast<void*>(node)) base(detail::sp_default(),
|
||||||
|
allocator, size);
|
||||||
|
detail::lsp_array_base& local = node->state();
|
||||||
|
local.set(node);
|
||||||
|
void* start = detail::sp_array_start<scalar>(node);
|
||||||
|
result.release();
|
||||||
|
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||||
|
static_cast<type*>(start), &local);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class A>
|
||||||
|
inline typename detail::lsp_if_size_array<T>::type
|
||||||
|
allocate_local_shared_noinit(const A& allocator)
|
||||||
|
{
|
||||||
|
typedef typename detail::sp_array_element<T>::type type;
|
||||||
|
typedef typename detail::sp_array_scalar<T>::type scalar;
|
||||||
|
typedef typename detail::sp_bind_allocator<A, scalar>::type other;
|
||||||
|
enum {
|
||||||
|
size = detail::sp_array_count<T>::value
|
||||||
|
};
|
||||||
|
typedef detail::lsp_size_array_state<other, size> state;
|
||||||
|
typedef detail::sp_array_base<state, false> base;
|
||||||
|
detail::sp_array_result<other, base> result(allocator, size);
|
||||||
|
base* node = result.get();
|
||||||
|
::new(static_cast<void*>(node)) base(detail::sp_default(),
|
||||||
|
allocator, size);
|
||||||
|
detail::lsp_array_base& local = node->state();
|
||||||
|
local.set(node);
|
||||||
|
void* start = detail::sp_array_start<scalar>(node);
|
||||||
|
result.release();
|
||||||
|
return local_shared_ptr<T>(detail::lsp_internal_constructor_tag(),
|
||||||
|
static_cast<type*>(start), &local);
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* boost */
|
||||||
|
|
||||||
|
#endif
|
@ -502,6 +502,10 @@ public:
|
|||||||
state_.size());
|
state_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T& state() BOOST_SP_NOEXCEPT {
|
||||||
|
return state_;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void dispose() {
|
virtual void dispose() {
|
||||||
sp_array_destroy<E>(state_.allocator(), sp_array_start<type>(this),
|
sp_array_destroy<E>(state_.allocator(), sp_array_start<type>(this),
|
||||||
state_.size());
|
state_.size());
|
||||||
|
@ -149,7 +149,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// internal constructor, used by make_shared
|
// internal constructor, used by make_shared
|
||||||
BOOST_CONSTEXPR local_shared_ptr( boost::detail::lsp_internal_constructor_tag, T * px_, boost::detail::local_counted_base * pn_ ) BOOST_SP_NOEXCEPT : px( px_ ), pn( pn_ )
|
BOOST_CONSTEXPR local_shared_ptr( boost::detail::lsp_internal_constructor_tag, element_type * px_, boost::detail::local_counted_base * pn_ ) BOOST_SP_NOEXCEPT : px( px_ ), pn( pn_ )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,63 +1,67 @@
|
|||||||
#ifndef BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP_INCLUDED
|
/*
|
||||||
#define BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP_INCLUDED
|
Copyright 2017 Peter Dimov
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
// make_local_shared_array.hpp
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
//
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// Copyright 2017 Peter Dimov
|
*/
|
||||||
//
|
#ifndef BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#define BOOST_SMART_PTR_MAKE_LOCAL_SHARED_ARRAY_HPP
|
||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// http://www.boost.org/LICENSE_1_0.txt
|
|
||||||
//
|
|
||||||
// See http://www.boost.org/libs/smart_ptr/ for documentation.
|
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/smart_ptr/allocate_local_shared_array.hpp>
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
|
||||||
#include <utility>
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
namespace boost
|
namespace boost {
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline typename detail::lsp_if_size_array<T>::type
|
||||||
|
make_local_shared()
|
||||||
{
|
{
|
||||||
|
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||||
namespace detail
|
detail::sp_array_scalar<T>::type>());
|
||||||
{
|
|
||||||
|
|
||||||
template<class T> struct lsp_if_array
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T> struct lsp_if_array<T[]>
|
|
||||||
{
|
|
||||||
typedef boost::local_shared_ptr<T[]> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T, std::size_t N> struct lsp_if_array<T[N]>
|
|
||||||
{
|
|
||||||
typedef boost::local_shared_ptr<T[N]> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template<class T, class... Args> typename boost::detail::lsp_if_array<T>::type make_local_shared( Args&&... args )
|
|
||||||
{
|
|
||||||
return boost::make_shared<T>( std::forward<Args>(args)... );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class... Args> typename boost::detail::lsp_if_array<T>::type make_local_shared_noinit( Args&&... args )
|
template<class T>
|
||||||
|
inline typename detail::lsp_if_size_array<T>::type
|
||||||
|
make_local_shared(const typename detail::sp_array_element<T>::type& value)
|
||||||
{
|
{
|
||||||
return boost::make_shared_noinit<T>( std::forward<Args>(args)... );
|
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||||
|
detail::sp_array_scalar<T>::type>(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class A, class... Args> typename boost::detail::lsp_if_array<T>::type allocate_local_shared( A const & a, Args&&... args )
|
template<class T>
|
||||||
|
inline typename detail::lsp_if_array<T>::type
|
||||||
|
make_local_shared(std::size_t size)
|
||||||
{
|
{
|
||||||
return boost::allocate_shared<T>( a, std::forward<Args>(args)... );
|
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||||
|
detail::sp_array_scalar<T>::type>(), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class A, class... Args> typename boost::detail::lsp_if_array<T>::type allocate_local_shared_noinit( A const & a, Args&&... args )
|
template<class T>
|
||||||
|
inline typename detail::lsp_if_array<T>::type
|
||||||
|
make_local_shared(std::size_t size,
|
||||||
|
const typename detail::sp_array_element<T>::type& value)
|
||||||
{
|
{
|
||||||
return boost::allocate_shared_noinit<T>( a, std::forward<Args>(args)... );
|
return boost::allocate_local_shared<T>(std::allocator<typename
|
||||||
|
detail::sp_array_scalar<T>::type>(), size, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace boost
|
template<class T>
|
||||||
|
inline typename detail::lsp_if_size_array<T>::type
|
||||||
|
make_local_shared_noinit()
|
||||||
|
{
|
||||||
|
return allocate_local_shared_noinit<T>(std::allocator<typename
|
||||||
|
detail::sp_array_scalar<T>::type>());
|
||||||
|
}
|
||||||
|
|
||||||
#endif // #ifndef BOOST_SMART_PTR_MAKE_SHARED_OBJECT_HPP_INCLUDED
|
template<class T>
|
||||||
|
inline typename detail::lsp_if_array<T>::type
|
||||||
|
make_local_shared_noinit(std::size_t size)
|
||||||
|
{
|
||||||
|
return allocate_local_shared_noinit<T>(std::allocator<typename
|
||||||
|
detail::sp_array_scalar<T>::type>(), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* boost */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
14
test/Jamfile
14
test/Jamfile
@ -242,6 +242,20 @@ run make_local_shared_esft_test.cpp ;
|
|||||||
run allocate_local_shared_test.cpp ;
|
run allocate_local_shared_test.cpp ;
|
||||||
run allocate_local_shared_esft_test.cpp ;
|
run allocate_local_shared_esft_test.cpp ;
|
||||||
|
|
||||||
|
run make_local_shared_array_test.cpp ;
|
||||||
|
run make_local_shared_arrays_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ;
|
||||||
|
run make_local_shared_array_throws_test.cpp ;
|
||||||
|
run make_local_shared_array_esft_test.cpp ;
|
||||||
|
run make_local_shared_array_noinit_test.cpp ;
|
||||||
|
run make_local_shared_array_value_test.cpp ;
|
||||||
|
run allocate_local_shared_array_test.cpp ;
|
||||||
|
run allocate_local_shared_arrays_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ;
|
||||||
|
run allocate_local_shared_array_throws_test.cpp ;
|
||||||
|
run allocate_local_shared_array_esft_test.cpp ;
|
||||||
|
run allocate_local_shared_array_noinit_test.cpp ;
|
||||||
|
run allocate_local_shared_array_value_test.cpp ;
|
||||||
|
run allocate_local_shared_array_construct_test.cpp ;
|
||||||
|
|
||||||
run local_sp_fn_test.cpp ;
|
run local_sp_fn_test.cpp ;
|
||||||
run lsp_convertible_test.cpp ;
|
run lsp_convertible_test.cpp ;
|
||||||
run lsp_convertible_test2.cpp ;
|
run lsp_convertible_test2.cpp ;
|
||||||
|
162
test/allocate_local_shared_array_construct_test.cpp
Normal file
162
test/allocate_local_shared_array_construct_test.cpp
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||||
|
struct allow { };
|
||||||
|
|
||||||
|
template<class T = void>
|
||||||
|
struct creator {
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
struct rebind {
|
||||||
|
typedef creator<U> other;
|
||||||
|
};
|
||||||
|
|
||||||
|
creator() { }
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
creator(const creator<U>&) { }
|
||||||
|
|
||||||
|
T* allocate(std::size_t size) {
|
||||||
|
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocate(T* ptr, std::size_t) {
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
void construct(U* ptr) {
|
||||||
|
::new(static_cast<void*>(ptr)) U(allow());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
void destroy(U* ptr) {
|
||||||
|
ptr->~U();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator==(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator!=(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
class type {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
explicit type(allow) {
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::allocate_local_shared<type[]>(creator<type>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[3]> result =
|
||||||
|
boost::allocate_local_shared<type[3]>(creator<type>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[][2]> result =
|
||||||
|
boost::allocate_local_shared<type[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[2][2]> result =
|
||||||
|
boost::allocate_local_shared<type[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[]> result =
|
||||||
|
boost::allocate_local_shared<const type[]>(creator<>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[3]> result =
|
||||||
|
boost::allocate_local_shared<const type[3]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[][2]> result =
|
||||||
|
boost::allocate_local_shared<const type[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[2][2]> result =
|
||||||
|
boost::allocate_local_shared<const type[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
94
test/allocate_local_shared_array_esft_test.cpp
Normal file
94
test/allocate_local_shared_array_esft_test.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
template<class T = void>
|
||||||
|
struct creator {
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
struct rebind {
|
||||||
|
typedef creator<U> other;
|
||||||
|
};
|
||||||
|
|
||||||
|
creator() { }
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
creator(const creator<U>&) { }
|
||||||
|
|
||||||
|
T* allocate(std::size_t size) {
|
||||||
|
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocate(T* ptr, std::size_t) {
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator==(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator!=(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
class type
|
||||||
|
: public boost::enable_shared_from_this<type> {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type() {
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::allocate_local_shared<type[]>(creator<type>(), 3);
|
||||||
|
try {
|
||||||
|
result[0].shared_from_this();
|
||||||
|
BOOST_ERROR("shared_from_this did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::allocate_local_shared_noinit<type[]>(creator<>(), 3);
|
||||||
|
try {
|
||||||
|
result[0].shared_from_this();
|
||||||
|
BOOST_ERROR("shared_from_this did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
245
test/allocate_local_shared_array_noinit_test.cpp
Normal file
245
test/allocate_local_shared_array_noinit_test.cpp
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/align/is_aligned.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
|
template<class T = void>
|
||||||
|
struct creator {
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
struct rebind {
|
||||||
|
typedef creator<U> other;
|
||||||
|
};
|
||||||
|
|
||||||
|
creator() { }
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
creator(const creator<U>&) { }
|
||||||
|
|
||||||
|
T* allocate(std::size_t size) {
|
||||||
|
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocate(T* ptr, std::size_t) {
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator==(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator!=(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
class type {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type()
|
||||||
|
: value_(0.0) {
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(long double value) {
|
||||||
|
value_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double get() const {
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
|
||||||
|
long double value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[]> result =
|
||||||
|
boost::allocate_local_shared_noinit<int[]>(creator<int>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[3]> result =
|
||||||
|
boost::allocate_local_shared_noinit<int[3]>(creator<int>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<int[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[2][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<int[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const int[]>(creator<>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[3]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const int[3]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const int[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[2][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const int[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::allocate_local_shared_noinit<type[]>(creator<type>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[3]> result =
|
||||||
|
boost::allocate_local_shared_noinit<type[3]>(creator<type>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[3]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<type[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<type[][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[2][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<type[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<type[2][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const type[]>(creator<>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<const type[]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[3]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const type[3]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<const type[3]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const
|
||||||
|
type[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<const type[][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[2][2]> result =
|
||||||
|
boost::allocate_local_shared_noinit<const type[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<const type[2][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
266
test/allocate_local_shared_array_test.cpp
Normal file
266
test/allocate_local_shared_array_test.cpp
Normal file
@ -0,0 +1,266 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/align/is_aligned.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
|
template<class T = void>
|
||||||
|
struct creator {
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
struct rebind {
|
||||||
|
typedef creator<U> other;
|
||||||
|
};
|
||||||
|
|
||||||
|
creator() { }
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
creator(const creator<U>&) { }
|
||||||
|
|
||||||
|
T* allocate(std::size_t size) {
|
||||||
|
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocate(T* ptr, std::size_t) {
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator==(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator!=(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
class type {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type()
|
||||||
|
: value_(0.0) {
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(long double value) {
|
||||||
|
value_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double get() const {
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
|
||||||
|
long double value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[]> result =
|
||||||
|
boost::allocate_local_shared<int[]>(creator<int>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[3]> result =
|
||||||
|
boost::allocate_local_shared<int[3]>(creator<int>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[][2]> result =
|
||||||
|
boost::allocate_local_shared<int[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[2][2]> result =
|
||||||
|
boost::allocate_local_shared<int[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[]> result =
|
||||||
|
boost::allocate_local_shared<const int[]>(creator<>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[3]> result =
|
||||||
|
boost::allocate_local_shared<const int[3]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[][2]> result =
|
||||||
|
boost::allocate_local_shared<const int[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[2][2]> result =
|
||||||
|
boost::allocate_local_shared<const int[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::allocate_local_shared<type[]>(creator<type>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[]> w1 = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[3]> result =
|
||||||
|
boost::allocate_local_shared<type[3]>(creator<type>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[3]> w1 = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[][2]> result =
|
||||||
|
boost::allocate_local_shared<type[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[2][2]> result =
|
||||||
|
boost::allocate_local_shared<type[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[]> result =
|
||||||
|
boost::allocate_local_shared<const type[]>(creator<>(), 3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[3]> result =
|
||||||
|
boost::allocate_local_shared<const type[3]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[][2]> result =
|
||||||
|
boost::allocate_local_shared<const type[][2]>(creator<>(), 2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[2][2]> result =
|
||||||
|
boost::allocate_local_shared<const type[2][2]>(creator<>());
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
121
test/allocate_local_shared_array_throws_test.cpp
Normal file
121
test/allocate_local_shared_array_throws_test.cpp
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
template<class T = void>
|
||||||
|
struct creator {
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
struct rebind {
|
||||||
|
typedef creator<U> other;
|
||||||
|
};
|
||||||
|
|
||||||
|
creator() { }
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
creator(const creator<U>&) { }
|
||||||
|
|
||||||
|
T* allocate(std::size_t size) {
|
||||||
|
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocate(T* ptr, std::size_t) {
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator==(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator!=(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
class type {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type() {
|
||||||
|
if (instances == 5) {
|
||||||
|
throw true;
|
||||||
|
}
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared<type[]>(creator<type>(), 6);
|
||||||
|
BOOST_ERROR("allocate_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared<type[][2]>(creator<type>(), 3);
|
||||||
|
BOOST_ERROR("allocate_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared<type[6]>(creator<>());
|
||||||
|
BOOST_ERROR("allocate_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared<type[3][2]>(creator<>());
|
||||||
|
BOOST_ERROR("allocate_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared_noinit<type[]>(creator<>(), 6);
|
||||||
|
BOOST_ERROR("allocate_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared_noinit<type[][2]>(creator<>(), 3);
|
||||||
|
BOOST_ERROR("allocate_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared_noinit<type[6]>(creator<>());
|
||||||
|
BOOST_ERROR("allocate_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::allocate_local_shared_noinit<type[3][2]>(creator<>());
|
||||||
|
BOOST_ERROR("allocate_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
83
test/allocate_local_shared_array_value_test.cpp
Normal file
83
test/allocate_local_shared_array_value_test.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
template<class T = void>
|
||||||
|
struct creator {
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
struct rebind {
|
||||||
|
typedef creator<U> other;
|
||||||
|
};
|
||||||
|
|
||||||
|
creator() { }
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
creator(const creator<U>&) { }
|
||||||
|
|
||||||
|
T* allocate(std::size_t size) {
|
||||||
|
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocate(T* ptr, std::size_t) {
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator==(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator!=(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[]> result =
|
||||||
|
boost::allocate_local_shared<int[]>(creator<int>(), 4, 1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[4]> result =
|
||||||
|
boost::allocate_local_shared<int[4]>(creator<int>(), 1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[]> result =
|
||||||
|
boost::allocate_local_shared<const int[]>(creator<>(), 4, 1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[4]> result =
|
||||||
|
boost::allocate_local_shared<const int[4]>(creator<>(), 1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
90
test/allocate_local_shared_arrays_test.cpp
Normal file
90
test/allocate_local_shared_arrays_test.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||||
|
template<class T = void>
|
||||||
|
struct creator {
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
struct rebind {
|
||||||
|
typedef creator<U> other;
|
||||||
|
};
|
||||||
|
|
||||||
|
creator() { }
|
||||||
|
|
||||||
|
template<class U>
|
||||||
|
creator(const creator<U>&) { }
|
||||||
|
|
||||||
|
T* allocate(std::size_t size) {
|
||||||
|
return static_cast<T*>(::operator new(sizeof(T) * size));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deallocate(T* ptr, std::size_t) {
|
||||||
|
::operator delete(ptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator==(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class U>
|
||||||
|
inline bool
|
||||||
|
operator!=(const creator<T>&, const creator<U>&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[][2]> result =
|
||||||
|
boost::allocate_local_shared<int[][2]>(creator<int>(), 2, {0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[2][2]> result =
|
||||||
|
boost::allocate_local_shared<int[2][2]>(creator<int>(), {0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[][2]> result =
|
||||||
|
boost::allocate_local_shared<const int[][2]>(creator<>(), 2, {0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[2][2]> result =
|
||||||
|
boost::allocate_local_shared<const int[2][2]>(creator<>(), {0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
57
test/make_local_shared_array_esft_test.cpp
Normal file
57
test/make_local_shared_array_esft_test.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
class type
|
||||||
|
: public boost::enable_shared_from_this<type> {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type() {
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::make_local_shared<type[]>(3);
|
||||||
|
try {
|
||||||
|
result[0].shared_from_this();
|
||||||
|
BOOST_ERROR("shared_from_this did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[3]> result =
|
||||||
|
boost::make_local_shared_noinit<type[3]>();
|
||||||
|
try {
|
||||||
|
result[0].shared_from_this();
|
||||||
|
BOOST_ERROR("shared_from_this did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
207
test/make_local_shared_array_noinit_test.cpp
Normal file
207
test/make_local_shared_array_noinit_test.cpp
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/align/is_aligned.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
|
class type {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type()
|
||||||
|
: value_(0.0) {
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(long double value) {
|
||||||
|
value_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double get() const {
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
|
||||||
|
long double value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[]> result =
|
||||||
|
boost::make_local_shared_noinit<int[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[3]> result =
|
||||||
|
boost::make_local_shared_noinit<int[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[][2]> result =
|
||||||
|
boost::make_local_shared_noinit<int[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[2][2]> result =
|
||||||
|
boost::make_local_shared_noinit<int[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[]> result =
|
||||||
|
boost::make_local_shared_noinit<const int[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[3]> result =
|
||||||
|
boost::make_local_shared_noinit<const int[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[][2]> result =
|
||||||
|
boost::make_local_shared_noinit<const int[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[2][2]> result =
|
||||||
|
boost::make_local_shared_noinit<const int[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::make_local_shared_noinit<type[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[3]> result =
|
||||||
|
boost::make_local_shared_noinit<type[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[3]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[][2]> result =
|
||||||
|
boost::make_local_shared_noinit<type[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<type[][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[2][2]> result =
|
||||||
|
boost::make_local_shared_noinit<type[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<type[2][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[]> result =
|
||||||
|
boost::make_local_shared_noinit<const type[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<const type[]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[3]> result =
|
||||||
|
boost::make_local_shared_noinit<const type[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<const type[3]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[][2]> result =
|
||||||
|
boost::make_local_shared_noinit<const type[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<const type[][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[2][2]> result =
|
||||||
|
boost::make_local_shared_noinit<const type[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
boost::weak_ptr<const type[2][2]> other = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
229
test/make_local_shared_array_test.cpp
Normal file
229
test/make_local_shared_array_test.cpp
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/align/is_aligned.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
#include <boost/smart_ptr/weak_ptr.hpp>
|
||||||
|
#include <boost/type_traits/alignment_of.hpp>
|
||||||
|
|
||||||
|
class type {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type()
|
||||||
|
: value_(0.0) {
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(long double value) {
|
||||||
|
value_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
long double get() const {
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
|
||||||
|
long double value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[]> result =
|
||||||
|
boost::make_local_shared<int[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[3]> result =
|
||||||
|
boost::make_local_shared<int[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[][2]> result =
|
||||||
|
boost::make_local_shared<int[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[2][2]> result =
|
||||||
|
boost::make_local_shared<int[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[]> result =
|
||||||
|
boost::make_local_shared<const int[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[3]> result =
|
||||||
|
boost::make_local_shared<const int[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0] == 0);
|
||||||
|
BOOST_TEST(result[1] == 0);
|
||||||
|
BOOST_TEST(result[2] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[][2]> result =
|
||||||
|
boost::make_local_shared<const int[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[2][2]> result =
|
||||||
|
boost::make_local_shared<const int[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<int>::value));
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 0);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[]> result =
|
||||||
|
boost::make_local_shared<type[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[]> w1 = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[3]> result =
|
||||||
|
boost::make_local_shared<type[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
boost::weak_ptr<type[3]> w1 = result;
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[][2]> result =
|
||||||
|
boost::make_local_shared<type[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<type[2][2]> result =
|
||||||
|
boost::make_local_shared<type[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[]> result =
|
||||||
|
boost::make_local_shared<const type[]>(3);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[3]> result =
|
||||||
|
boost::make_local_shared<const type[3]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 3);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[][2]> result =
|
||||||
|
boost::make_local_shared<const type[][2]>(2);
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const type[2][2]> result =
|
||||||
|
boost::make_local_shared<const type[2][2]>();
|
||||||
|
BOOST_TEST(result.get() != 0);
|
||||||
|
BOOST_TEST(result.local_use_count() == 1);
|
||||||
|
BOOST_TEST(boost::alignment::is_aligned(result.get(),
|
||||||
|
boost::alignment_of<type>::value));
|
||||||
|
BOOST_TEST(type::instances == 4);
|
||||||
|
result.reset();
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
84
test/make_local_shared_array_throws_test.cpp
Normal file
84
test/make_local_shared_array_throws_test.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
class type {
|
||||||
|
public:
|
||||||
|
static unsigned instances;
|
||||||
|
|
||||||
|
type() {
|
||||||
|
if (instances == 5) {
|
||||||
|
throw true;
|
||||||
|
}
|
||||||
|
++instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
~type() {
|
||||||
|
--instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
type(const type&);
|
||||||
|
type& operator=(const type&);
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned type::instances = 0;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
boost::make_local_shared<type[]>(6);
|
||||||
|
BOOST_ERROR("make_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::make_local_shared<type[][2]>(3);
|
||||||
|
BOOST_ERROR("make_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::make_local_shared<type[6]>();
|
||||||
|
BOOST_ERROR("make_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::make_local_shared<type[3][2]>();
|
||||||
|
BOOST_ERROR("make_local_shared did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::make_local_shared_noinit<type[]>(6);
|
||||||
|
BOOST_ERROR("make_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::make_local_shared_noinit<type[][2]>(3);
|
||||||
|
BOOST_ERROR("make_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::make_local_shared_noinit<type[6]>();
|
||||||
|
BOOST_ERROR("make_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
boost::make_local_shared_noinit<type[3][2]>();
|
||||||
|
BOOST_ERROR("make_local_shared_noinit did not throw");
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_TEST(type::instances == 0);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
46
test/make_local_shared_array_value_test.cpp
Normal file
46
test/make_local_shared_array_value_test.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[]> result =
|
||||||
|
boost::make_local_shared<int[]>(4, 1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[4]> result =
|
||||||
|
boost::make_local_shared<int[4]>(1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[]> result =
|
||||||
|
boost::make_local_shared<const int[]>(4, 1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[4]> result =
|
||||||
|
boost::make_local_shared<const int[4]>(1);
|
||||||
|
BOOST_TEST(result[0] == 1);
|
||||||
|
BOOST_TEST(result[1] == 1);
|
||||||
|
BOOST_TEST(result[2] == 1);
|
||||||
|
BOOST_TEST(result[3] == 1);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
53
test/make_local_shared_arrays_test.cpp
Normal file
53
test/make_local_shared_arrays_test.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2017 Glen Joseph Fernandes
|
||||||
|
(glenjofe@gmail.com)
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_local_shared.hpp>
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[][2]> result =
|
||||||
|
boost::make_local_shared<int[][2]>(2, {0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<int[2][2]> result =
|
||||||
|
boost::make_local_shared<int[2][2]>({0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[][2]> result =
|
||||||
|
boost::make_local_shared<const int[][2]>(2, {0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
boost::local_shared_ptr<const int[2][2]> result =
|
||||||
|
boost::make_local_shared<const int[2][2]>({0, 1});
|
||||||
|
BOOST_TEST(result[0][0] == 0);
|
||||||
|
BOOST_TEST(result[0][1] == 1);
|
||||||
|
BOOST_TEST(result[1][0] == 0);
|
||||||
|
BOOST_TEST(result[1][1] == 1);
|
||||||
|
}
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
Reference in New Issue
Block a user