forked from boostorg/smart_ptr
For allocate_shared and make_shared: Separate test case that g++ does support yet. Remove macros testing for no partial specialization in traits. Add additional traits.
[SVN r81261]
This commit is contained in:
@ -19,8 +19,8 @@ namespace boost {
|
|||||||
template<typename T, typename A>
|
template<typename T, typename A>
|
||||||
inline typename detail::sp_if_array<T>::type
|
inline typename detail::sp_if_array<T>::type
|
||||||
allocate_shared(const A& allocator, size_t size) {
|
allocate_shared(const A& allocator, size_t size) {
|
||||||
typedef typename shared_ptr<T>::element_type T1;
|
typedef typename detail::array_inner<T>::type T1;
|
||||||
typedef typename detail::array_type<T1>::type T2;
|
typedef typename detail::array_base<T1>::type T2;
|
||||||
T1* p1 = 0;
|
T1* p1 = 0;
|
||||||
T2* p2 = 0;
|
T2* p2 = 0;
|
||||||
size_t n1 = size * detail::array_size<T1>::size;
|
size_t n1 = size * detail::array_size<T1>::size;
|
||||||
@ -37,8 +37,8 @@ namespace boost {
|
|||||||
template<typename T, typename A, typename... Args>
|
template<typename T, typename A, typename... Args>
|
||||||
inline typename detail::sp_if_array<T>::type
|
inline typename detail::sp_if_array<T>::type
|
||||||
allocate_shared(const A& allocator, size_t size, Args&&... args) {
|
allocate_shared(const A& allocator, size_t size, Args&&... args) {
|
||||||
typedef typename shared_ptr<T>::element_type T1;
|
typedef typename detail::array_inner<T>::type T1;
|
||||||
typedef typename detail::array_type<T1>::type T2;
|
typedef typename detail::array_base<T1>::type T2;
|
||||||
T1* p1 = 0;
|
T1* p1 = 0;
|
||||||
T2* p2 = 0;
|
T2* p2 = 0;
|
||||||
size_t n1 = size * detail::array_size<T1>::size;
|
size_t n1 = size * detail::array_size<T1>::size;
|
||||||
@ -56,8 +56,8 @@ namespace boost {
|
|||||||
template<typename T, typename A>
|
template<typename T, typename A>
|
||||||
inline typename detail::sp_if_array<T>::type
|
inline typename detail::sp_if_array<T>::type
|
||||||
allocate_shared(const A& allocator, typename detail::array_list<T>::type list) {
|
allocate_shared(const A& allocator, typename detail::array_list<T>::type list) {
|
||||||
typedef typename shared_ptr<T>::element_type T1;
|
typedef typename detail::array_inner<T>::type T1;
|
||||||
typedef typename detail::array_type<T1>::type T2;
|
typedef typename detail::array_base<T1>::type T2;
|
||||||
typedef const T2 T3;
|
typedef const T2 T3;
|
||||||
T1* p1 = 0;
|
T1* p1 = 0;
|
||||||
T2* p2 = 0;
|
T2* p2 = 0;
|
||||||
|
@ -13,43 +13,45 @@
|
|||||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#endif
|
#endif
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct array_type {
|
struct array_base {
|
||||||
typedef typename boost::remove_cv<T>::type type;
|
typedef typename boost::remove_cv<T>::type type;
|
||||||
};
|
};
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
template<typename T, std::size_t N>
|
||||||
template<typename T, size_t N>
|
struct array_base<T[N]> {
|
||||||
struct array_type<T[N]> {
|
typedef typename array_base<T>::type type;
|
||||||
typedef typename array_type<T>::type type;
|
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct array_size {
|
struct array_size {
|
||||||
enum {
|
enum {
|
||||||
size = 1
|
size = 1
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
template<typename T, std::size_t N>
|
||||||
template<typename T, size_t N>
|
|
||||||
struct array_size<T[N]> {
|
struct array_size<T[N]> {
|
||||||
enum {
|
enum {
|
||||||
size = N * array_size<T>::size
|
size = N * array_size<T>::size
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
struct array_inner {
|
||||||
|
};
|
||||||
|
template<typename T>
|
||||||
|
struct array_inner<T[]> {
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||||
|
template<typename T>
|
||||||
struct array_list {
|
struct array_list {
|
||||||
};
|
};
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct array_list<T[]> {
|
struct array_list<T[]> {
|
||||||
typedef std::initializer_list<T> type;
|
typedef std::initializer_list<T> type;
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,14 @@ namespace boost {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct sp_if_array {
|
struct sp_if_array {
|
||||||
};
|
};
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct sp_if_array<T[]> {
|
struct sp_if_array<T[]> {
|
||||||
typedef boost::shared_ptr<T[]> type;
|
typedef boost::shared_ptr<T[]> type;
|
||||||
};
|
};
|
||||||
#endif
|
template<typename T, size_t N>
|
||||||
|
struct sp_if_array<T[N]> {
|
||||||
|
typedef boost::shared_ptr<T[N]> type;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ namespace boost {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline typename detail::sp_if_array<T>::type
|
inline typename detail::sp_if_array<T>::type
|
||||||
make_shared(std::size_t size) {
|
make_shared(std::size_t size) {
|
||||||
typedef typename shared_ptr<T>::element_type T1;
|
typedef typename detail::array_inner<T>::type T1;
|
||||||
typedef typename detail::array_type<T1>::type T2;
|
typedef typename detail::array_base<T1>::type T2;
|
||||||
T1* p1 = 0;
|
T1* p1 = 0;
|
||||||
T2* p2 = 0;
|
T2* p2 = 0;
|
||||||
size_t n1 = size * detail::array_size<T1>::size;
|
size_t n1 = size * detail::array_size<T1>::size;
|
||||||
@ -37,8 +37,8 @@ namespace boost {
|
|||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
inline typename detail::sp_if_array<T>::type
|
inline typename detail::sp_if_array<T>::type
|
||||||
make_shared(std::size_t size, Args&&... args) {
|
make_shared(std::size_t size, Args&&... args) {
|
||||||
typedef typename shared_ptr<T>::element_type T1;
|
typedef typename detail::array_inner<T>::type T1;
|
||||||
typedef typename detail::array_type<T1>::type T2;
|
typedef typename detail::array_base<T1>::type T2;
|
||||||
T1* p1 = 0;
|
T1* p1 = 0;
|
||||||
T2* p2 = 0;
|
T2* p2 = 0;
|
||||||
size_t n1 = size * detail::array_size<T1>::size;
|
size_t n1 = size * detail::array_size<T1>::size;
|
||||||
@ -56,8 +56,8 @@ namespace boost {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline typename detail::sp_if_array<T>::type
|
inline typename detail::sp_if_array<T>::type
|
||||||
make_shared(typename detail::array_list<T>::type list) {
|
make_shared(typename detail::array_list<T>::type list) {
|
||||||
typedef typename shared_ptr<T>::element_type T1;
|
typedef typename detail::array_inner<T>::type T1;
|
||||||
typedef typename detail::array_type<T1>::type T2;
|
typedef typename detail::array_base<T1>::type T2;
|
||||||
typedef const T2 T3;
|
typedef const T2 T3;
|
||||||
T1* p1 = 0;
|
T1* p1 = 0;
|
||||||
T2* p2 = 0;
|
T2* p2 = 0;
|
||||||
@ -77,8 +77,8 @@ namespace boost {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline typename detail::sp_if_array<T>::type
|
inline typename detail::sp_if_array<T>::type
|
||||||
make_shared_noinit(std::size_t size) {
|
make_shared_noinit(std::size_t size) {
|
||||||
typedef typename shared_ptr<T>::element_type T1;
|
typedef typename detail::array_inner<T>::type T1;
|
||||||
typedef typename detail::array_type<T1>::type T2;
|
typedef typename detail::array_base<T1>::type T2;
|
||||||
T1* p1 = 0;
|
T1* p1 = 0;
|
||||||
T2* p2 = 0;
|
T2* p2 = 0;
|
||||||
size_t n1 = size * detail::array_size<T1>::size;
|
size_t n1 = size * detail::array_size<T1>::size;
|
||||||
|
@ -134,12 +134,14 @@ import testing ;
|
|||||||
[ run make_shared_array_test.cpp ]
|
[ run make_shared_array_test.cpp ]
|
||||||
[ run make_shared_arrays_test.cpp ]
|
[ run make_shared_arrays_test.cpp ]
|
||||||
[ run make_shared_array_create_test.cpp ]
|
[ run make_shared_array_create_test.cpp ]
|
||||||
|
[ run make_shared_arrays_create_test.cpp ]
|
||||||
[ run make_shared_array_throws_test.cpp ]
|
[ run make_shared_array_throws_test.cpp ]
|
||||||
[ run make_shared_array_esft_test.cpp ]
|
[ run make_shared_array_esft_test.cpp ]
|
||||||
[ run make_shared_array_args_test.cpp ]
|
[ run make_shared_array_args_test.cpp ]
|
||||||
[ run allocate_shared_array_test.cpp ]
|
[ run allocate_shared_array_test.cpp ]
|
||||||
[ run allocate_shared_arrays_test.cpp ]
|
[ run allocate_shared_arrays_test.cpp ]
|
||||||
[ run allocate_shared_array_create_test.cpp ]
|
[ run allocate_shared_array_create_test.cpp ]
|
||||||
|
[ run allocate_shared_arrays_create_test.cpp ]
|
||||||
[ run allocate_shared_array_throws_test.cpp ]
|
[ run allocate_shared_array_throws_test.cpp ]
|
||||||
[ run allocate_shared_array_esft_test.cpp ]
|
[ run allocate_shared_array_esft_test.cpp ]
|
||||||
;
|
;
|
||||||
|
23
test/allocate_shared_arrays_create_test.cpp
Normal file
23
test/allocate_shared_arrays_create_test.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||||
|
* glenfe at live dot com
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License,
|
||||||
|
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||||
|
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/allocate_shared_array.hpp>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||||
|
{
|
||||||
|
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
|
||||||
|
BOOST_TEST(a1[0][0] == 0);
|
||||||
|
BOOST_TEST(a1[0][1] == 1);
|
||||||
|
BOOST_TEST(a1[1][0] == 2);
|
||||||
|
BOOST_TEST(a1[1][1] == 3);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
23
test/make_shared_arrays_create_test.cpp
Normal file
23
test/make_shared_arrays_create_test.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||||
|
* glenfe at live dot com
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License,
|
||||||
|
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||||
|
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <boost/smart_ptr/make_shared_array.hpp>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||||
|
{
|
||||||
|
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>({ {0, 1}, {2, 3} });
|
||||||
|
BOOST_TEST(a1[0][0] == 0);
|
||||||
|
BOOST_TEST(a1[0][1] == 1);
|
||||||
|
BOOST_TEST(a1[1][0] == 2);
|
||||||
|
BOOST_TEST(a1[1][1] == 3);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user