summaryrefslogtreecommitdiff
path: root/libs/container/test
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2015-04-08 03:09:47 +0000
committer <>2015-05-05 14:37:32 +0000
commitf2541bb90af059680aa7036f315f052175999355 (patch)
treea5b214744b256f07e1dc2bd7273035a7808c659f /libs/container/test
parented232fdd34968697a68783b3195b1da4226915b5 (diff)
downloadboost-tarball-master.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_58_0.tar.bz2.HEADboost_1_58_0master
Diffstat (limited to 'libs/container/test')
-rw-r--r--libs/container/test/alloc_full_test.cpp1
-rw-r--r--libs/container/test/allocator_traits_test.cpp227
-rw-r--r--libs/container/test/check_equal_containers.hpp31
-rw-r--r--libs/container/test/container_common_tests.hpp86
-rw-r--r--libs/container/test/default_init_test.hpp33
-rw-r--r--libs/container/test/deque_test.cpp55
-rw-r--r--libs/container/test/dummy_test_allocator.hpp51
-rw-r--r--libs/container/test/emplace_test.hpp5
-rw-r--r--libs/container/test/expand_bwd_test_allocator.hpp41
-rw-r--r--libs/container/test/expand_bwd_test_template.hpp21
-rw-r--r--libs/container/test/explicit_inst_deque_test.cpp26
-rw-r--r--libs/container/test/explicit_inst_flat_map_test.cpp28
-rw-r--r--libs/container/test/explicit_inst_flat_set_test.cpp28
-rw-r--r--libs/container/test/explicit_inst_list_test.cpp26
-rw-r--r--libs/container/test/explicit_inst_map_test.cpp28
-rw-r--r--libs/container/test/explicit_inst_set_test.cpp28
-rw-r--r--libs/container/test/explicit_inst_slist_test.cpp26
-rw-r--r--libs/container/test/explicit_inst_stable_vector_test.cpp26
-rw-r--r--libs/container/test/explicit_inst_static_vector_test.cpp26
-rw-r--r--libs/container/test/explicit_inst_string_test.cpp20
-rw-r--r--libs/container/test/explicit_inst_vector_test.cpp26
-rw-r--r--libs/container/test/flat_map_test.cpp147
-rw-r--r--libs/container/test/flat_set_test.cpp92
-rw-r--r--libs/container/test/input_from_forward_iterator.hpp16
-rw-r--r--libs/container/test/insert_test.hpp3
-rw-r--r--libs/container/test/insert_vs_emplace_test.cpp8
-rw-r--r--libs/container/test/list_test.cpp40
-rw-r--r--libs/container/test/list_test.hpp134
-rw-r--r--libs/container/test/map_test.cpp114
-rw-r--r--libs/container/test/map_test.hpp159
-rw-r--r--libs/container/test/null_iterators_test.cpp5
-rw-r--r--libs/container/test/print_container.hpp21
-rw-r--r--libs/container/test/propagate_allocator_test.hpp435
-rw-r--r--libs/container/test/scoped_allocator_adaptor_test.cpp148
-rw-r--r--libs/container/test/scoped_allocator_usage_test.cpp201
-rw-r--r--libs/container/test/set_test.cpp98
-rw-r--r--libs/container/test/set_test.hpp130
-rw-r--r--libs/container/test/slist_test.cpp29
-rw-r--r--libs/container/test/small_vector_test.cpp183
-rw-r--r--libs/container/test/stable_vector_test.cpp30
-rw-r--r--libs/container/test/static_vector_test.cpp10
-rw-r--r--libs/container/test/static_vector_test.hpp3
-rw-r--r--libs/container/test/string_test.cpp43
-rw-r--r--libs/container/test/vector_test.cpp20
-rw-r--r--libs/container/test/vector_test.hpp96
45 files changed, 2134 insertions, 870 deletions
diff --git a/libs/container/test/alloc_full_test.cpp b/libs/container/test/alloc_full_test.cpp
index a2835523b..1ffc2a9d9 100644
--- a/libs/container/test/alloc_full_test.cpp
+++ b/libs/container/test/alloc_full_test.cpp
@@ -15,7 +15,6 @@
#include <vector>
#include <iostream>
-#include <utility>
#include <cstring>
#include <algorithm> //std::remove
#include <boost/container/detail/alloc_lib_auto_link.hpp>
diff --git a/libs/container/test/allocator_traits_test.cpp b/libs/container/test/allocator_traits_test.cpp
index 407a62b49..3f4dff0c8 100644
--- a/libs/container/test/allocator_traits_test.cpp
+++ b/libs/container/test/allocator_traits_test.cpp
@@ -11,18 +11,25 @@
#include <cstddef>
#include <boost/container/allocator_traits.hpp>
#include <boost/static_assert.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/type_traits/integral_constant.hpp>
+#include <boost/container/detail/type_traits.hpp>
#include <boost/container/detail/function_detector.hpp>
#include <boost/move/utility_core.hpp>
#include <memory>
+#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+#include <boost/move/detail/fwd_macros.hpp>
+#endif
+#include <boost/core/lightweight_test.hpp>
template<class T>
class SimpleAllocator
{
+ public:
bool allocate_called_;
bool deallocate_called_;
- public:
+
+ typedef boost::container::container_detail::
+ true_type is_always_equal;
+
typedef T value_type;
template <class U>
@@ -47,15 +54,26 @@ class SimpleAllocator
bool deallocate_called() const
{ return deallocate_called_; }
+
+ friend bool operator==(const SimpleAllocator &, const SimpleAllocator &)
+ { return true; }
+
+ friend bool operator!=(const SimpleAllocator &, const SimpleAllocator &)
+ { return false; }
};
template<class T>
class SimpleSmartPtr
{
+ void unspecified_bool_type_func() const {}
+ typedef void (SimpleSmartPtr::*unspecified_bool_type)() const;
+
public:
- SimpleSmartPtr()
- : ptr_(0)
+ typedef T* pointer;
+
+ explicit SimpleSmartPtr(pointer p = 0)
+ : ptr_(p)
{}
SimpleSmartPtr(const SimpleSmartPtr &c)
@@ -64,7 +82,8 @@ class SimpleSmartPtr
SimpleSmartPtr & operator=(const SimpleSmartPtr &c)
{ this->ptr_ = c.ptr_; }
- typedef T* pointer;
+ operator unspecified_bool_type() const
+ { return ptr_? &SimpleSmartPtr::unspecified_bool_type_func : 0; }
private:
T *ptr_;
@@ -73,6 +92,7 @@ class SimpleSmartPtr
template<class T>
class ComplexAllocator
{
+ public:
bool allocate_called_;
bool deallocate_called_;
bool allocate_hint_called_;
@@ -80,8 +100,8 @@ class ComplexAllocator
mutable bool max_size_called_;
mutable bool select_on_container_copy_construction_called_;
bool construct_called_;
+ mutable bool storage_is_unpropagable_;
- public:
typedef T value_type;
typedef SimpleSmartPtr<T> pointer;
typedef SimpleSmartPtr<const T> const_pointer;
@@ -93,9 +113,14 @@ class ComplexAllocator
typedef SimpleSmartPtr<const void> const_void_pointer;
typedef signed short difference_type;
typedef unsigned short size_type;
- typedef boost::true_type propagate_on_container_copy_assignment;
- typedef boost::true_type propagate_on_container_move_assignment;
- typedef boost::true_type propagate_on_container_swap;
+ typedef boost::container::container_detail::
+ true_type propagate_on_container_copy_assignment;
+ typedef boost::container::container_detail::
+ true_type propagate_on_container_move_assignment;
+ typedef boost::container::container_detail::
+ true_type propagate_on_container_swap;
+ typedef boost::container::container_detail::
+ true_type is_partially_propagable;
ComplexAllocator()
: allocate_called_(false)
@@ -127,23 +152,30 @@ class ComplexAllocator
size_type max_size() const
{ max_size_called_ = true; return size_type(size_type(0)-1); }
- #define BOOST_PP_LOCAL_MACRO(n) \
- template<class U BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) > \
- void construct(U *p BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
- { \
- construct_called_ = true; \
- ::new (p) U (BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- } \
+ #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+
+ #define BOOST_CONTAINER_COMPLEXALLOCATOR_CONSTRUCT_IMPL(N)\
+ \
+ template< class U BOOST_MOVE_I##N BOOST_MOVE_CLASS##N > \
+ void construct(U *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N) \
+ { construct_called_ = true; ::new(p) U ( BOOST_MOVE_FWD##N ); }\
//
- #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
- #include BOOST_PP_LOCAL_ITERATE()
+ BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_COMPLEXALLOCATOR_CONSTRUCT_IMPL)
+ #undef BOOST_CONTAINER_COMPLEXALLOCATOR_CONSTRUCT_IMPL
+ #else
+
+ template< class U, class ...Args>
+ void construct(U *p, BOOST_FWD_REF(Args) ...args)
+ { construct_called_ = true; ::new(p) U( ::boost::forward<Args>(args)...); }
+
+ #endif
template<class U>
void construct(U *p, boost::container::default_init_t)
- {
- construct_called_ = true;
- ::new (p) U;
- }
+ { construct_called_ = true; ::new(p)U; }
+
+ bool storage_is_unpropagable(pointer p) const
+ { storage_is_unpropagable_ = true; return !p; }
//getters
bool allocate_called() const
@@ -166,6 +198,9 @@ class ComplexAllocator
bool construct_called() const
{ return construct_called_; }
+
+ bool storage_is_unpropagable_called() const
+ { return storage_is_unpropagable_; }
};
class copymovable
@@ -212,22 +247,23 @@ void test_void_allocator()
int main()
{
+ using namespace boost::container::container_detail;
test_void_allocator();
//SimpleAllocator
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::value_type, int>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::pointer, int*>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::const_pointer, const int*>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::void_pointer, void*>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::const_void_pointer, const void*>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::difference_type, std::ptrdiff_t>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::size_type, std::size_t>::value ));
BOOST_STATIC_ASSERT(( boost::container::allocator_traits
< SimpleAllocator<int> >::propagate_on_container_copy_assignment::value == false ));
@@ -235,27 +271,31 @@ int main()
< SimpleAllocator<int> >::propagate_on_container_move_assignment::value == false ));
BOOST_STATIC_ASSERT(( boost::container::allocator_traits
< SimpleAllocator<int> >::propagate_on_container_swap::value == false ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( boost::container::allocator_traits
+ < SimpleAllocator<int> >::is_always_equal::value == true ));
+ BOOST_STATIC_ASSERT(( boost::container::allocator_traits
+ < SimpleAllocator<int> >::is_partially_propagable::value == false ));
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::rebind_traits<double>::allocator_type
, SimpleAllocator<double> >::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< SimpleAllocator<int> >::rebind_alloc<double>::value_type
, double >::value ));
//ComplexAllocator
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::value_type, int>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::pointer, SimpleSmartPtr<int> >::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::const_pointer, SimpleSmartPtr<const int> >::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::void_pointer, SimpleSmartPtr<void> >::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::const_void_pointer, SimpleSmartPtr<const void> >::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::difference_type, signed short>::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::size_type, unsigned short>::value ));
BOOST_STATIC_ASSERT(( boost::container::allocator_traits
< ComplexAllocator<int> >::propagate_on_container_copy_assignment::value == true ));
@@ -263,10 +303,14 @@ int main()
< ComplexAllocator<int> >::propagate_on_container_move_assignment::value == true ));
BOOST_STATIC_ASSERT(( boost::container::allocator_traits
< ComplexAllocator<int> >::propagate_on_container_swap::value == true ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( boost::container::allocator_traits
+ < ComplexAllocator<int> >::is_always_equal::value == false ));
+ BOOST_STATIC_ASSERT(( boost::container::allocator_traits
+ < ComplexAllocator<int> >::is_partially_propagable::value == true ));
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::rebind_traits<double>::allocator_type
, ComplexAllocator<double> >::value ));
- BOOST_STATIC_ASSERT(( boost::is_same<boost::container::allocator_traits
+ BOOST_STATIC_ASSERT(( is_same<boost::container::allocator_traits
< ComplexAllocator<int> >::rebind_alloc<double>::value_type
, double >::value ));
@@ -279,51 +323,43 @@ int main()
//allocate
CAllocTraits::allocate(c_alloc, 1);
- if(!c_alloc.allocate_called()){
- return 1;
- }
+ BOOST_TEST(c_alloc.allocate_called());
+
SAllocTraits::allocate(s_alloc, 1);
- if(!s_alloc.allocate_called()){
- return 1;
- }
+ BOOST_TEST(s_alloc.allocate_called());
//deallocate
CAllocTraits::deallocate(c_alloc, CAllocTraits::pointer(), 1);
- if(!c_alloc.deallocate_called()){
- return 1;
- }
+ BOOST_TEST(c_alloc.deallocate_called());
+
SAllocTraits::deallocate(s_alloc, SAllocTraits::pointer(), 1);
- if(!s_alloc.deallocate_called()){
- return 1;
- }
+ BOOST_TEST(s_alloc.deallocate_called());
//allocate with hint
CAllocTraits::allocate(c_alloc, 1, CAllocTraits::const_void_pointer());
- if(!c_alloc.allocate_hint_called()){
- return 1;
- }
+ BOOST_TEST(c_alloc.allocate_hint_called());
+
+ s_alloc.allocate_called_ = false;
SAllocTraits::allocate(s_alloc, 1, SAllocTraits::const_void_pointer());
+ BOOST_TEST(s_alloc.allocate_called());
//destroy
float dummy;
CAllocTraits::destroy(c_alloc, &dummy);
- if(!c_alloc.destroy_called()){
- return 1;
- }
+ BOOST_TEST(c_alloc.destroy_called());
+
SAllocTraits::destroy(s_alloc, &dummy);
//max_size
CAllocTraits::max_size(c_alloc);
- if(!c_alloc.max_size_called()){
- return 1;
- }
- SAllocTraits::max_size(s_alloc);
+ BOOST_TEST(c_alloc.max_size_called());
+
+ BOOST_TEST(SAllocTraits::size_type(-1)/sizeof(SAllocTraits::value_type) == SAllocTraits::max_size(s_alloc));
//select_on_container_copy_construction
CAllocTraits::select_on_container_copy_construction(c_alloc);
- if(!c_alloc.select_on_container_copy_construction_called()){
- return 1;
- }
+ BOOST_TEST(c_alloc.select_on_container_copy_construction_called());
+
SAllocTraits::select_on_container_copy_construction(s_alloc);
//construct
@@ -332,81 +368,80 @@ int main()
c.copymoveconstructed_ = true;
c.copymoveconstructed_ = true;
CAllocTraits::construct(c_alloc, &c);
- if(!c_alloc.construct_called() || c.copymoveconstructed() || c.moved()){
- return 1;
- }
+ BOOST_TEST(c_alloc.construct_called() && !c.copymoveconstructed() && !c.moved());
}
{
int i = 5;
CAllocTraits::construct(c_alloc, &i, boost::container::default_init);
- if(!c_alloc.construct_called() || i != 5){
- return 1;
- }
+ BOOST_TEST(c_alloc.construct_called() && i == 5);
}
{
copymovable c;
copymovable c2;
CAllocTraits::construct(c_alloc, &c, c2);
- if(!c_alloc.construct_called() || !c.copymoveconstructed() || c.moved()){
- return 1;
- }
+ BOOST_TEST(c_alloc.construct_called() && c.copymoveconstructed() && !c.moved());
}
{
copymovable c;
copymovable c2;
CAllocTraits::construct(c_alloc, &c, ::boost::move(c2));
- if(!c_alloc.construct_called() || !c.copymoveconstructed() || !c.moved()){
- return 1;
- }
+ BOOST_TEST(c_alloc.construct_called() && c.copymoveconstructed() && c.moved());
}
{
copymovable c;
c.copymoveconstructed_ = true;
c.copymoveconstructed_ = true;
SAllocTraits::construct(s_alloc, &c);
- if(c.copymoveconstructed() || c.moved()){
- return 1;
- }
+ BOOST_TEST(!c.copymoveconstructed() && !c.moved());
}
{
int i = 4;
SAllocTraits::construct(s_alloc, &i, boost::container::default_init);
- if(i != 4){
- return 1;
- }
+ BOOST_TEST(i == 4);
}
{
copymovable c;
copymovable c2;
SAllocTraits::construct(s_alloc, &c, c2);
- if(!c.copymoveconstructed() || c.moved()){
- return 1;
- }
+ BOOST_TEST(c.copymoveconstructed() && !c.moved());
}
{
copymovable c;
copymovable c2;
SAllocTraits::construct(s_alloc, &c, ::boost::move(c2));
- if(!c.copymoveconstructed() || !c.moved()){
- return 1;
- }
+ BOOST_TEST(c.copymoveconstructed() && c.moved());
}
{
copymovable c;
CAllocTraits::construct(c_alloc, &c, 0, 1, 2);
- if(!c_alloc.construct_called() || c.copymoveconstructed() || c.moved()){
- return 1;
- }
+ BOOST_TEST(c_alloc.construct_called() && !c.copymoveconstructed() && !c.moved());
}
{
copymovable c;
copymovable c2;
SAllocTraits::construct(s_alloc, &c, 0, 1, 2);
- if(c.copymoveconstructed() || c.moved()){
- return 1;
+ BOOST_TEST(!c.copymoveconstructed() && !c.moved());
+ }
+ //storage_is_unpropagable
+ {
+ SAlloc s_alloc2;
+ BOOST_TEST(!SAllocTraits::storage_is_unpropagable(s_alloc, SAllocTraits::pointer()));
+ }
+ {
+ {
+ CAlloc c_alloc2;
+ CAlloc::value_type v;
+ BOOST_TEST(!CAllocTraits::storage_is_unpropagable(c_alloc, CAllocTraits::pointer(&v)));
+ BOOST_TEST(c_alloc.storage_is_unpropagable_called());
+ }
+ {
+ CAlloc c_alloc2;
+ BOOST_TEST( CAllocTraits::storage_is_unpropagable(c_alloc2, CAllocTraits::pointer()));
+ BOOST_TEST(c_alloc2.storage_is_unpropagable_called());
}
+
}
- return 0;
+ return ::boost::report_errors();
}
#include <boost/container/detail/config_end.hpp>
diff --git a/libs/container/test/check_equal_containers.hpp b/libs/container/test/check_equal_containers.hpp
index b742891b9..0f67a6a4e 100644
--- a/libs/container/test/check_equal_containers.hpp
+++ b/libs/container/test/check_equal_containers.hpp
@@ -14,11 +14,11 @@
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/pair.hpp>
#include <boost/container/detail/mpl.hpp>
-#include <functional>
-#include <iostream>
-#include <algorithm>
#include <boost/move/unique_ptr.hpp>
+#include <cstddef>
+#include <boost/container/detail/iterator.hpp>
+
namespace boost{
namespace container {
namespace test{
@@ -59,22 +59,26 @@ bool CheckEqual( const Pair1 &pair1, const Pair2 &pair2
}
//Function to check if both containers are equal
-template<class MyBoostCont
- ,class MyStdCont>
-bool CheckEqualContainers(const MyBoostCont &boostcont, const MyStdCont &stdcont)
+template<class ContA
+ ,class ContB>
+bool CheckEqualContainers(const ContA &cont_a, const ContB &cont_b)
{
- if(boostcont.size() != stdcont.size())
+ if(cont_a.size() != cont_b.size())
return false;
- typename MyBoostCont::const_iterator itboost(boostcont.begin()), itboostend(boostcont.end());
- typename MyStdCont::const_iterator itstd(stdcont.begin());
- typename MyStdCont::size_type dist = (typename MyStdCont::size_type)std::distance(itboost, itboostend);
- if(dist != boostcont.size()){
+ typename ContA::const_iterator itcont_a(cont_a.begin()), itcont_a_end(cont_a.end());
+ typename ContB::const_iterator itcont_b(cont_b.begin()), itcont_b_end(cont_b.end());;
+ typename ContB::size_type dist = (typename ContB::size_type)boost::container::iterator_distance(itcont_a, itcont_a_end);
+ if(dist != cont_a.size()){
+ return false;
+ }
+ typename ContA::size_type dist2 = (typename ContA::size_type)boost::container::iterator_distance(itcont_b, itcont_b_end);
+ if(dist2 != cont_b.size()){
return false;
}
std::size_t i = 0;
- for(; itboost != itboostend; ++itboost, ++itstd, ++i){
- if(!CheckEqual(*itstd, *itboost))
+ for(; itcont_a != itcont_a_end; ++itcont_a, ++itcont_b, ++i){
+ if(!CheckEqual(*itcont_a, *itcont_b))
return false;
}
return true;
@@ -101,6 +105,7 @@ bool CheckEqualPairContainers(const MyBoostCont &boostcont, const MyStdCont &std
}
return true;
}
+
} //namespace test{
} //namespace container {
} //namespace boost{
diff --git a/libs/container/test/container_common_tests.hpp b/libs/container/test/container_common_tests.hpp
new file mode 100644
index 000000000..af57eb640
--- /dev/null
+++ b/libs/container/test/container_common_tests.hpp
@@ -0,0 +1,86 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
+#define BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
+
+#include <boost/container/detail/config_begin.hpp>
+
+namespace boost{
+namespace container {
+namespace test{
+
+
+template<class Container>
+const Container &as_const(Container &c)
+{ return c; }
+
+//nth, index_of
+template<class Container>
+bool test_nth_index_of(Container &c)
+{
+ typename Container::iterator it;
+ typename Container::const_iterator cit;
+ typename Container::size_type sz, csz;
+ //index 0
+ it = c.nth(0);
+ sz = c.index_of(it);
+ cit = as_const(c).nth(0);
+ csz = as_const(c).index_of(cit);
+
+ if(it != c.begin())
+ return false;
+ if(cit != c.cbegin())
+ return false;
+ if(sz != 0)
+ return false;
+ if(csz != 0)
+ return false;
+
+ //index size()/2
+ const typename Container::size_type sz_div_2 = c.size()/2;
+ it = c.nth(sz_div_2);
+ sz = c.index_of(it);
+ cit = as_const(c).nth(sz_div_2);
+ csz = as_const(c).index_of(cit);
+
+ if(it != (c.begin()+sz_div_2))
+ return false;
+ if(cit != (c.cbegin()+sz_div_2))
+ return false;
+ if(sz != sz_div_2)
+ return false;
+ if(csz != sz_div_2)
+ return false;
+
+ //index size()
+ it = c.nth(c.size());
+ sz = c.index_of(it);
+ cit = as_const(c).nth(c.size());
+ csz = as_const(c).index_of(cit);
+
+ if(it != c.end())
+ return false;
+ if(cit != c.cend())
+ return false;
+ if(sz != c.size())
+ return false;
+ if(csz != c.size())
+ return false;
+ return true;
+}
+
+} //namespace test{
+} //namespace container {
+} //namespace boost{
+
+#include <boost/container/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
diff --git a/libs/container/test/default_init_test.hpp b/libs/container/test/default_init_test.hpp
index 4af9d5988..aa64ab01b 100644
--- a/libs/container/test/default_init_test.hpp
+++ b/libs/container/test/default_init_test.hpp
@@ -12,27 +12,7 @@
#define BOOST_CONTAINER_TEST_DEFAULT_INIT_TEST_HEADER
#include <boost/container/detail/config_begin.hpp>
-#include <algorithm>
-#include <memory>
-#include <vector>
-#include <iostream>
-#include <functional>
-#include <list>
-
-#include <boost/move/utility_core.hpp>
-#include <boost/container/detail/mpl.hpp>
-#include "print_container.hpp"
-#include "check_equal_containers.hpp"
-#include "movable_int.hpp"
-#include <string>
-#include <vector>
-#include "emplace_test.hpp"
-#include "input_from_forward_iterator.hpp"
-#include <boost/move/utility_core.hpp>
-#include <boost/move/iterator.hpp>
-#include <boost/core/no_exceptions_support.hpp>
-#include <boost/static_assert.hpp>
-#include "insert_test.hpp"
+#include <cstddef>
namespace boost{
namespace container {
@@ -141,6 +121,17 @@ bool default_init_test()//Test for default initialization
}
}
{
+ test::default_init_allocator<int>::reset_pattern(0);
+ test::default_init_allocator<int>::set_ascending(true);
+ IntDefaultInitAllocVector v(Capacity, default_init, test::default_init_allocator<int>());
+ typename IntDefaultInitAllocVector::iterator it = v.begin();
+ //Compare with the pattern
+ for(std::size_t i = 0; i != Capacity; ++i, ++it){
+ if(!test::check_ascending_byte_pattern(*it))
+ return false;
+ }
+ }
+ {
test::default_init_allocator<int>::reset_pattern(100);
test::default_init_allocator<int>::set_ascending(false);
IntDefaultInitAllocVector v;
diff --git a/libs/container/test/deque_test.cpp b/libs/container/test/deque_test.cpp
index 4e0b30e27..3a32e6bf5 100644
--- a/libs/container/test/deque_test.cpp
+++ b/libs/container/test/deque_test.cpp
@@ -9,11 +9,9 @@
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
-#include <algorithm>
#include <memory>
#include <deque>
#include <iostream>
-#include <functional>
#include <list>
#include <boost/container/deque.hpp>
@@ -337,36 +335,21 @@ int test_cont_variants()
return 0;
}
-bool test_support_for_initialization_list()
-{
-#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
- const std::initializer_list<int> il = {1, 10, 11};
- const deque<int> expectedDeque(il.begin(), il.end());
-
- const deque<int> testConstructor = il;
- if(testConstructor != expectedDeque)
- return false;
-
- deque<int> testAssignmentOperator = {11, 12, 23};
- testAssignmentOperator = il;
- if(testConstructor != expectedDeque)
- return false;
+struct boost_container_deque;
- deque<int> testAssignmentMethod = {11, 12, 23};
- testAssignmentMethod.assign(il);
- if(testConstructor != expectedDeque)
- return false;
+namespace boost { namespace container { namespace test {
- deque<int> testInsertMethod = {11};
- testInsertMethod.insert(testInsertMethod.cbegin(), {12, 23});
- if(testConstructor != expectedDeque)
- return false;
-
- return true;
-#endif
- return true;
+template<>
+struct alloc_propagate_base<boost_container_deque>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::deque<T, Allocator> type;
+ };
+};
-}
+}}} //namespace boost::container::test
int main ()
{
@@ -422,9 +405,6 @@ int main ()
return 1;
}
- if(!test_support_for_initialization_list())
- return 1;
-
////////////////////////////////////
// Emplace testing
////////////////////////////////////
@@ -436,8 +416,17 @@ int main ()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<deque>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_deque>())
+ return 1;
+
+ ////////////////////////////////////
+ // Initializer lists testing
+ ////////////////////////////////////
+ if(!boost::container::test::test_vector_methods_with_initializer_list_as_argument_for
+ < boost::container::deque<int> >()) {
return 1;
+ }
+ return 0;
return 0;
}
diff --git a/libs/container/test/dummy_test_allocator.hpp b/libs/container/test/dummy_test_allocator.hpp
index 3ecfc98c1..a9f0b8252 100644
--- a/libs/container/test/dummy_test_allocator.hpp
+++ b/libs/container/test/dummy_test_allocator.hpp
@@ -11,23 +11,32 @@
#ifndef BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
#define BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
-#if defined(_MSC_VER)
+#ifndef BOOST_CONFIG_HPP
+# include <boost/config.hpp>
+#endif
+
+#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
-
#include <boost/container/container_fwd.hpp>
+
+#include <boost/container/throw_exception.hpp>
+
+#include <boost/container/detail/addressof.hpp>
#include <boost/container/detail/allocation_type.hpp>
-#include <boost/assert.hpp>
-#include <boost/container/detail/utilities.hpp>
-#include <boost/container/detail/type_traits.hpp>
#include <boost/container/detail/mpl.hpp>
-#include <boost/container/detail/version_type.hpp>
#include <boost/container/detail/multiallocation_chain.hpp>
-#include <boost/container/throw_exception.hpp>
+#include <boost/container/detail/type_traits.hpp>
+#include <boost/container/detail/version_type.hpp>
+
#include <boost/move/utility_core.hpp>
+#include <boost/move/adl_move_swap.hpp>
+
+#include <boost/assert.hpp>
+
#include <memory>
#include <algorithm>
#include <cstddef>
@@ -135,12 +144,8 @@ class dummy_test_allocator
//Experimental version 2 dummy_test_allocator functions
- std::pair<pointer, bool>
- allocation_command(boost::container::allocation_type,
- size_type,
- size_type,
- size_type &, const pointer & = 0)
- { return std::pair<pointer, bool>(pointer(), true); }
+ pointer allocation_command(boost::container::allocation_type, size_type, size_type &, pointer &p)
+ { p = pointer(); return pointer(); }
//!Returns maximum the number of objects the previously allocated memory
//!pointed by p can hold.
@@ -233,7 +238,7 @@ class propagation_test_allocator
{ return CopyOnPropagateOnContSwap ? propagation_test_allocator(*this) : propagation_test_allocator(); }
explicit propagation_test_allocator()
- : id_(unique_id_++)
+ : id_(++unique_id_)
, ctr_copies_(0)
, ctr_moves_(0)
, assign_copies_(0)
@@ -258,7 +263,7 @@ class propagation_test_allocator
, PropagateOnContSwap
, CopyOnPropagateOnContSwap> &x)
: id_(x.id_)
- , ctr_copies_(0)
+ , ctr_copies_(x.ctr_copies_+1)
, ctr_moves_(0)
, assign_copies_(0)
, assign_moves_(0)
@@ -296,8 +301,8 @@ class propagation_test_allocator
return *this;
}
- static void reset_unique_id()
- { unique_id_ = 0; }
+ static void reset_unique_id(unsigned id = 0)
+ { unique_id_ = id; }
T* allocate(std::size_t n)
{ return (T*)::new char[sizeof(T)*n]; }
@@ -314,12 +319,12 @@ class propagation_test_allocator
void swap(propagation_test_allocator &r)
{
++this->swaps_; ++r.swaps_;
- boost::container::swap_dispatch(this->id_, r.id_);
- boost::container::swap_dispatch(this->ctr_copies_, r.ctr_copies_);
- boost::container::swap_dispatch(this->ctr_moves_, r.ctr_moves_);
- boost::container::swap_dispatch(this->assign_copies_, r.assign_copies_);
- boost::container::swap_dispatch(this->assign_moves_, r.assign_moves_);
- boost::container::swap_dispatch(this->swaps_, r.swaps_);
+ boost::adl_move_swap(this->id_, r.id_);
+ boost::adl_move_swap(this->ctr_copies_, r.ctr_copies_);
+ boost::adl_move_swap(this->ctr_moves_, r.ctr_moves_);
+ boost::adl_move_swap(this->assign_copies_, r.assign_copies_);
+ boost::adl_move_swap(this->assign_moves_, r.assign_moves_);
+ boost::adl_move_swap(this->swaps_, r.swaps_);
}
friend void swap(propagation_test_allocator &l, propagation_test_allocator &r)
diff --git a/libs/container/test/emplace_test.hpp b/libs/container/test/emplace_test.hpp
index 62824c5a2..50fe65642 100644
--- a/libs/container/test/emplace_test.hpp
+++ b/libs/container/test/emplace_test.hpp
@@ -16,8 +16,7 @@
#include <boost/container/detail/workaround.hpp>
#include <boost/container/detail/mpl.hpp>
#include <boost/move/utility_core.hpp>
-#include <boost/container/detail/utilities.hpp>
-#include <boost/aligned_storage.hpp>
+#include <boost/container/detail/type_traits.hpp>
namespace boost{
namespace container {
@@ -147,7 +146,7 @@ bool test_expected_container(const Container &ec, const std::pair<EmplaceInt, Em
static EmplaceInt expected [10];
typedef std::pair<EmplaceInt, EmplaceInt> EmplaceIntPair;
-static boost::aligned_storage<sizeof(EmplaceIntPair)*10>::type pair_storage;
+static boost::container::container_detail::aligned_storage<sizeof(EmplaceIntPair)*10>::type pair_storage;
static EmplaceIntPair* initialize_emplace_int_pair()
{
diff --git a/libs/container/test/expand_bwd_test_allocator.hpp b/libs/container/test/expand_bwd_test_allocator.hpp
index f7ba3049d..2e1609384 100644
--- a/libs/container/test/expand_bwd_test_allocator.hpp
+++ b/libs/container/test/expand_bwd_test_allocator.hpp
@@ -11,19 +11,28 @@
#ifndef BOOST_CONTAINER_EXPAND_BWD_TEST_ALLOCATOR_HPP
#define BOOST_CONTAINER_EXPAND_BWD_TEST_ALLOCATOR_HPP
-#if defined(_MSC_VER)
+#ifndef BOOST_CONFIG_HPP
+# include <boost/config.hpp>
+#endif
+
+#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
-
#include <boost/container/container_fwd.hpp>
+
#include <boost/container/throw_exception.hpp>
+
+#include <boost/container/detail/addressof.hpp>
#include <boost/container/detail/allocation_type.hpp>
-#include <boost/assert.hpp>
-#include <boost/container/detail/utilities.hpp>
#include <boost/container/detail/version_type.hpp>
+
+#include <boost/move/adl_move_swap.hpp>
+
+#include <boost/assert.hpp>
+
#include <memory>
#include <algorithm>
#include <cstddef>
@@ -109,42 +118,40 @@ class expand_bwd_test_allocator
friend void swap(self_t &alloc1, self_t &alloc2)
{
- boost::container::swap_dispatch(alloc1.mp_buffer, alloc2.mp_buffer);
- boost::container::swap_dispatch(alloc1.m_size, alloc2.m_size);
- boost::container::swap_dispatch(alloc1.m_offset, alloc2.m_offset);
+ boost::adl_move_swap(alloc1.mp_buffer, alloc2.mp_buffer);
+ boost::adl_move_swap(alloc1.m_size, alloc2.m_size);
+ boost::adl_move_swap(alloc1.m_offset, alloc2.m_offset);
}
//Experimental version 2 expand_bwd_test_allocator functions
- std::pair<pointer, bool>
- allocation_command(boost::container::allocation_type command,
- size_type limit_size,
- size_type preferred_size,
- size_type &received_size, const pointer &reuse = 0)
+ pointer allocation_command(boost::container::allocation_type command,
+ size_type limit_size,size_type &prefer_in_recvd_out_size,pointer &reuse)
{
- (void)preferred_size; (void)reuse; (void)command;
+ (void)reuse; (void)command;
//This allocator only expands backwards!
assert(m_allocations == 0 || (command & boost::container::expand_bwd));
- received_size = limit_size;
+ prefer_in_recvd_out_size = limit_size;
if(m_allocations == 0){
if((m_offset + limit_size) > m_size){
assert(0);
}
++m_allocations;
- return std::pair<pointer, bool>(mp_buffer + m_offset, false);
+ reuse = 0;
+ return (mp_buffer + m_offset);
}
else if(m_allocations == 1){
if(limit_size > m_size){
assert(0);
}
++m_allocations;
- return std::pair<pointer, bool>(mp_buffer, true);
+ return mp_buffer;
}
else{
throw_bad_alloc();
- return std::pair<pointer, bool>(mp_buffer, true);
+ return mp_buffer;
}
}
diff --git a/libs/container/test/expand_bwd_test_template.hpp b/libs/container/test/expand_bwd_test_template.hpp
index 7d6486df3..1c193ac66 100644
--- a/libs/container/test/expand_bwd_test_template.hpp
+++ b/libs/container/test/expand_bwd_test_template.hpp
@@ -14,10 +14,10 @@
#include <boost/container/detail/config_begin.hpp>
#include <vector>
#include <typeinfo>
+#include <iostream>
#include "expand_bwd_test_allocator.hpp"
-#include <algorithm>
+#include <boost/container/detail/algorithm.hpp> //equal()
#include "movable_int.hpp"
-#include <boost/type_traits/remove_volatile.hpp>
#include <boost/move/make_unique.hpp>
namespace boost { namespace container { namespace test {
@@ -28,7 +28,7 @@ bool CheckEqualVector(const Vector1 &vector1, const Vector2 &vector2)
{
if(vector1.size() != vector2.size())
return false;
- return std::equal(vector1.begin(), vector1.end(), vector2.begin());
+ return boost::container::algo_equal(vector1.begin(), vector1.end(), vector2.begin());
}
template<class Vector>
@@ -55,8 +55,7 @@ template<class VectorWithExpandBwdAllocator>
bool test_insert_with_expand_bwd()
{
typedef typename VectorWithExpandBwdAllocator::value_type value_type;
- typedef typename boost::remove_volatile<value_type>::type non_volatile_value_type;
- typedef std::vector<non_volatile_value_type> Vect;
+ typedef std::vector<value_type> Vect;
const unsigned int MemorySize = 1000;
//Distance old and new buffer
@@ -79,12 +78,15 @@ bool test_insert_with_expand_bwd()
{ 0, 100, 200 };
for(unsigned int pos = 0; pos < sizeof(Position)/sizeof(Position[0]); ++pos){
+ if(!life_count<value_type>::check(0))
+ return false;
+
for(unsigned int iteration = 0; iteration < Iterations; ++iteration)
{
boost::movelib::unique_ptr<char[]> memptr =
boost::movelib::make_unique_definit<char[]>(MemorySize*sizeof(value_type));
value_type *memory = (value_type*)memptr.get();
- std::vector<non_volatile_value_type> initial_data;
+ std::vector<value_type> initial_data;
initial_data.resize(InitialSize[iteration]);
for(unsigned int i = 0; i < InitialSize[iteration]; ++i){
initial_data[i] = i;
@@ -122,6 +124,8 @@ bool test_insert_with_expand_bwd()
return false;
}
}
+ if(!life_count<value_type>::check(0))
+ return false;
}
return true;
@@ -133,7 +137,6 @@ template<class VectorWithExpandBwdAllocator>
bool test_assign_with_expand_bwd()
{
typedef typename VectorWithExpandBwdAllocator::value_type value_type;
- typedef typename boost::remove_volatile<value_type>::type non_volatile_value_type;
const unsigned int MemorySize = 200;
const unsigned int Offset[] = { 50, 50, 50};
@@ -147,14 +150,14 @@ bool test_assign_with_expand_bwd()
boost::movelib::make_unique_definit<char[]>(MemorySize*sizeof(value_type));
value_type *memory = (value_type*)memptr.get();
//Create initial data
- std::vector<non_volatile_value_type> initial_data;
+ std::vector<value_type> initial_data;
initial_data.resize(InitialSize[iteration]);
for(unsigned int i = 0; i < InitialSize[iteration]; ++i){
initial_data[i] = i;
}
//Create data to assign
- std::vector<non_volatile_value_type> data_to_insert;
+ std::vector<value_type> data_to_insert;
data_to_insert.resize(InsertSize[iteration]);
for(unsigned int i = 0; i < InsertSize[iteration]; ++i){
data_to_insert[i] = -i;
diff --git a/libs/container/test/explicit_inst_deque_test.cpp b/libs/container/test/explicit_inst_deque_test.cpp
new file mode 100644
index 000000000..77163db94
--- /dev/null
+++ b/libs/container/test/explicit_inst_deque_test.cpp
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/deque.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::deque<empty>;
+
+int main()
+{
+ ::boost::container::deque<empty> dummy;
+ (void)dummy;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_flat_map_test.cpp b/libs/container/test/explicit_inst_flat_map_test.cpp
new file mode 100644
index 000000000..77925d8cc
--- /dev/null
+++ b/libs/container/test/explicit_inst_flat_map_test.cpp
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/flat_map.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::flat_map<empty, empty>;
+template class ::boost::container::flat_multimap<empty, empty>;
+
+int main()
+{
+ ::boost::container::flat_map<empty, empty> dummy;
+ ::boost::container::flat_multimap<empty, empty> dummy2;
+ (void)dummy; (void)dummy2;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_flat_set_test.cpp b/libs/container/test/explicit_inst_flat_set_test.cpp
new file mode 100644
index 000000000..a9c482f9f
--- /dev/null
+++ b/libs/container/test/explicit_inst_flat_set_test.cpp
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/flat_set.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::flat_set<empty>;
+template class ::boost::container::flat_multiset<empty>;
+
+int main()
+{
+ ::boost::container::flat_set<empty> dummy;
+ ::boost::container::flat_multiset<empty> dummy2;
+ (void)dummy; (void)dummy2;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_list_test.cpp b/libs/container/test/explicit_inst_list_test.cpp
new file mode 100644
index 000000000..b038594e7
--- /dev/null
+++ b/libs/container/test/explicit_inst_list_test.cpp
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/list.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::list<empty>;
+
+int main()
+{
+ ::boost::container::list<empty> dummy;
+ (void)dummy;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_map_test.cpp b/libs/container/test/explicit_inst_map_test.cpp
new file mode 100644
index 000000000..4a19429fc
--- /dev/null
+++ b/libs/container/test/explicit_inst_map_test.cpp
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/map.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::map<empty, empty>;
+template class ::boost::container::multimap<empty, empty>;
+
+int main()
+{
+ ::boost::container::map<empty, empty> dummy;
+ ::boost::container::multimap<empty, empty> dummy2;
+ (void)dummy; (void)dummy2;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_set_test.cpp b/libs/container/test/explicit_inst_set_test.cpp
new file mode 100644
index 000000000..7116c9641
--- /dev/null
+++ b/libs/container/test/explicit_inst_set_test.cpp
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/set.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::set<empty>;
+template class ::boost::container::multiset<empty>;
+
+int main()
+{
+ ::boost::container::set<empty> dummy;
+ ::boost::container::multiset<empty> dummy2;
+ (void)dummy; (void)dummy2;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_slist_test.cpp b/libs/container/test/explicit_inst_slist_test.cpp
new file mode 100644
index 000000000..ed4b5ae9c
--- /dev/null
+++ b/libs/container/test/explicit_inst_slist_test.cpp
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/slist.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::slist<empty>;
+
+int main()
+{
+ ::boost::container::slist<empty> dummy;
+ (void)dummy;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_stable_vector_test.cpp b/libs/container/test/explicit_inst_stable_vector_test.cpp
new file mode 100644
index 000000000..cdd3bdd87
--- /dev/null
+++ b/libs/container/test/explicit_inst_stable_vector_test.cpp
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/stable_vector.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::stable_vector<empty>;
+
+int main()
+{
+ ::boost::container::stable_vector<empty> dummy;
+ (void)dummy;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_static_vector_test.cpp b/libs/container/test/explicit_inst_static_vector_test.cpp
new file mode 100644
index 000000000..6681f7cd2
--- /dev/null
+++ b/libs/container/test/explicit_inst_static_vector_test.cpp
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/static_vector.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::static_vector<empty, 2>;
+
+int main()
+{
+ ::boost::container::static_vector<empty, 2> dummy;
+ (void)dummy;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_string_test.cpp b/libs/container/test/explicit_inst_string_test.cpp
new file mode 100644
index 000000000..f911bb03f
--- /dev/null
+++ b/libs/container/test/explicit_inst_string_test.cpp
@@ -0,0 +1,20 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/string.hpp>
+
+template class ::boost::container::basic_string<char>;
+
+int main()
+{
+ ::boost::container::basic_string<char> dummy;
+ (void)dummy;
+ return 0;
+}
diff --git a/libs/container/test/explicit_inst_vector_test.cpp b/libs/container/test/explicit_inst_vector_test.cpp
new file mode 100644
index 000000000..b03427ceb
--- /dev/null
+++ b/libs/container/test/explicit_inst_vector_test.cpp
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/container/vector.hpp>
+
+struct empty
+{
+ friend bool operator == (const empty &, const empty &){ return true; }
+ friend bool operator < (const empty &, const empty &){ return true; }
+};
+
+template class ::boost::container::vector<empty>;
+
+int main()
+{
+ ::boost::container::vector<empty> dummy;
+ (void)dummy;
+ return 0;
+}
diff --git a/libs/container/test/flat_map_test.cpp b/libs/container/test/flat_map_test.cpp
index b0ae33021..8a8ec0895 100644
--- a/libs/container/test/flat_map_test.cpp
+++ b/libs/container/test/flat_map_test.cpp
@@ -13,15 +13,19 @@
#include <boost/container/allocator.hpp>
#include <boost/container/node_allocator.hpp>
#include <boost/container/adaptive_pool.hpp>
+#include <boost/container/detail/flat_tree.hpp>
#include "print_container.hpp"
#include "dummy_test_allocator.hpp"
#include "movable_int.hpp"
#include "map_test.hpp"
#include "propagate_allocator_test.hpp"
+#include "container_common_tests.hpp"
#include "emplace_test.hpp"
+
#include <vector>
-#include <boost/container/detail/flat_tree.hpp>
+#include <map>
+
using namespace boost::container;
@@ -179,7 +183,7 @@ public:
flat_multimap<recursive_flat_multimap, recursive_flat_multimap>::const_iterator cit_;
flat_multimap<recursive_flat_multimap, recursive_flat_multimap>::reverse_iterator rit_;
flat_multimap<recursive_flat_multimap, recursive_flat_multimap>::const_reverse_iterator crit_;
-
+
friend bool operator< (const recursive_flat_multimap &a, const recursive_flat_multimap &b)
{ return a.id_ < b.id_; }
};
@@ -195,40 +199,6 @@ void test_move()
move_assign.swap(original);
}
-template<class T, class A>
-class flat_map_propagate_test_wrapper
- : public boost::container::flat_map
- < T, T, std::less<T>
- , typename boost::container::allocator_traits<A>::template
- portable_rebind_alloc< std::pair<T, T> >::type>
-{
- BOOST_COPYABLE_AND_MOVABLE(flat_map_propagate_test_wrapper)
- typedef boost::container::flat_map
- < T, T, std::less<T>
- , typename boost::container::allocator_traits<A>::template
- portable_rebind_alloc< std::pair<T, T> >::type> Base;
- public:
- flat_map_propagate_test_wrapper()
- : Base()
- {}
-
- flat_map_propagate_test_wrapper(const flat_map_propagate_test_wrapper &x)
- : Base(x)
- {}
-
- flat_map_propagate_test_wrapper(BOOST_RV_REF(flat_map_propagate_test_wrapper) x)
- : Base(boost::move(static_cast<Base&>(x)))
- {}
-
- flat_map_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(flat_map_propagate_test_wrapper) x)
- { this->Base::operator=(x); return *this; }
-
- flat_map_propagate_test_wrapper &operator=(BOOST_RV_REF(flat_map_propagate_test_wrapper) x)
- { this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
-
- void swap(flat_map_propagate_test_wrapper &x)
- { this->Base::swap(x); }
-};
namespace boost{
namespace container {
@@ -343,6 +313,49 @@ struct GetAllocatorMap
};
};
+struct boost_container_flat_map;
+struct boost_container_flat_multimap;
+
+namespace boost { namespace container { namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_flat_map>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef typename boost::container::allocator_traits<Allocator>::
+ template portable_rebind_alloc<std::pair<T, T> >::type TypeAllocator;
+ typedef boost::container::flat_map<T, T, std::less<T>, TypeAllocator> type;
+ };
+};
+
+template<>
+struct alloc_propagate_base<boost_container_flat_multimap>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef typename boost::container::allocator_traits<Allocator>::
+ template portable_rebind_alloc<std::pair<T, T> >::type TypeAllocator;
+ typedef boost::container::flat_multimap<T, T, std::less<T>, TypeAllocator> type;
+ };
+};
+
+template <class Key, class T, class Compare, class Allocator>
+struct get_real_stored_allocator<flat_map<Key, T, Compare, Allocator> >
+{
+ typedef typename flat_map<Key, T, Compare, Allocator>::impl_stored_allocator_type type;
+};
+
+template <class Key, class T, class Compare, class Allocator>
+struct get_real_stored_allocator<flat_multimap<Key, T, Compare, Allocator> >
+{
+ typedef typename flat_multimap<Key, T, Compare, Allocator>::impl_stored_allocator_type type;
+};
+
+}}} //namespace boost::container::test
+
template<class VoidAllocator>
int test_map_variants()
{
@@ -398,53 +411,36 @@ int test_map_variants()
return 0;
}
-template<typename FlatMapType>
-bool test_support_for_initialization_list_for()
-{
-#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
- const std::initializer_list<std::pair<int, int>> il
- = {std::make_pair(1, 2), std::make_pair(3, 4)};
-
- const FlatMapType expected(il.begin(), il.end());
- {
- const FlatMapType sil = il;
- if (sil != expected)
- return false;
-
- const FlatMapType sil_ordered(ordered_unique_range, il);
- if(sil_ordered != expected)
- return false;
-
- FlatMapType sil_assign = {std::make_pair(99, 100)};
- sil_assign = il;
- if(sil_assign != expected)
- return false;
- }
- {
- FlatMapType sil;
- sil.insert(il);
- if(sil != expected)
- return false;
- }
- return true;
-#endif
- return true;
-}
-
int main()
{
using namespace boost::container::test;
//Allocator argument container
{
- flat_map<int, int> map_((std::allocator<std::pair<int, int> >()));
- flat_multimap<int, int> multimap_((std::allocator<std::pair<int, int> >()));
+ flat_map<int, int> map_((flat_map<int, int>::allocator_type()));
+ flat_multimap<int, int> multimap_((flat_multimap<int, int>::allocator_type()));
}
//Now test move semantics
{
test_move<flat_map<recursive_flat_map, recursive_flat_map> >();
test_move<flat_multimap<recursive_flat_multimap, recursive_flat_multimap> >();
}
+ //Now test nth/index_of
+ {
+ flat_map<int, int> map;
+ flat_multimap<int, int> mmap;
+
+ map.insert(std::pair<int, int>(0, 0));
+ map.insert(std::pair<int, int>(1, 0));
+ map.insert(std::pair<int, int>(2, 0));
+ mmap.insert(std::pair<int, int>(0, 0));
+ mmap.insert(std::pair<int, int>(1, 0));
+ mmap.insert(std::pair<int, int>(2, 0));
+ if(!boost::container::test::test_nth_index_of(map))
+ return 1;
+ if(!boost::container::test::test_nth_index_of(mmap))
+ return 1;
+ }
////////////////////////////////////
// Ordered insertion test
@@ -477,10 +473,10 @@ int main()
return 1;
}
- if(!test_support_for_initialization_list_for<flat_map<int, int> >())
+ if(!boost::container::test::test_map_support_for_initialization_list_for<flat_map<int, int> >())
return 1;
- if(!test_support_for_initialization_list_for<flat_multimap<int, int> >())
+ if (!boost::container::test::test_map_support_for_initialization_list_for<flat_multimap<int, int> >())
return 1;
////////////////////////////////////
@@ -496,7 +492,10 @@ int main()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<flat_map_propagate_test_wrapper>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_flat_map>())
+ return 1;
+
+ if(!boost::container::test::test_propagate_allocator<boost_container_flat_multimap>())
return 1;
return 0;
diff --git a/libs/container/test/flat_set_test.cpp b/libs/container/test/flat_set_test.cpp
index 9e9e8c9d4..26b5a6395 100644
--- a/libs/container/test/flat_set_test.cpp
+++ b/libs/container/test/flat_set_test.cpp
@@ -21,6 +21,7 @@
#include "set_test.hpp"
#include "propagate_allocator_test.hpp"
#include "emplace_test.hpp"
+#include "container_common_tests.hpp"
#include <vector>
#include <boost/container/detail/flat_tree.hpp>
@@ -183,7 +184,7 @@ class recursive_flat_set
flat_set<recursive_flat_set>::const_iterator cit_;
flat_set<recursive_flat_set>::reverse_iterator rit_;
flat_set<recursive_flat_set>::const_reverse_iterator crit_;
-
+
friend bool operator< (const recursive_flat_set &a, const recursive_flat_set &b)
{ return a.id_ < b.id_; }
};
@@ -209,7 +210,7 @@ class recursive_flat_multiset
flat_multiset<recursive_flat_multiset>::const_iterator cit_;
flat_multiset<recursive_flat_multiset>::reverse_iterator rit_;
flat_multiset<recursive_flat_multiset>::const_reverse_iterator crit_;
-
+
friend bool operator< (const recursive_flat_multiset &a, const recursive_flat_multiset &b)
{ return a.id_ < b.id_; }
};
@@ -226,35 +227,6 @@ void test_move()
move_assign.swap(original);
}
-template<class T, class A>
-class flat_set_propagate_test_wrapper
- : public boost::container::flat_set<T, std::less<T>, A>
-{
- BOOST_COPYABLE_AND_MOVABLE(flat_set_propagate_test_wrapper)
- typedef boost::container::flat_set<T, std::less<T>, A> Base;
- public:
- flat_set_propagate_test_wrapper()
- : Base()
- {}
-
- flat_set_propagate_test_wrapper(const flat_set_propagate_test_wrapper &x)
- : Base(x)
- {}
-
- flat_set_propagate_test_wrapper(BOOST_RV_REF(flat_set_propagate_test_wrapper) x)
- : Base(boost::move(static_cast<Base&>(x)))
- {}
-
- flat_set_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(flat_set_propagate_test_wrapper) x)
- { this->Base::operator=(x); return *this; }
-
- flat_set_propagate_test_wrapper &operator=(BOOST_RV_REF(flat_set_propagate_test_wrapper) x)
- { this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
-
- void swap(flat_set_propagate_test_wrapper &x)
- { this->Base::swap(x); }
-};
-
namespace boost{
namespace container {
namespace test{
@@ -517,20 +489,65 @@ bool test_support_for_initialization_list_for()
return true;
}
+struct boost_container_flat_set;
+struct boost_container_flat_multiset;
+
+namespace boost {
+namespace container {
+namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_flat_set>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::flat_set<T, std::less<T>, Allocator> type;
+ };
+};
+
+template<>
+struct alloc_propagate_base<boost_container_flat_multiset>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::flat_multiset<T, std::less<T>, Allocator> type;
+ };
+};
+
+}}} //boost::container::test
+
int main()
{
using namespace boost::container::test;
//Allocator argument container
{
- flat_set<int> set_((std::allocator<int>()));
- flat_multiset<int> multiset_((std::allocator<int>()));
+ flat_set<int> set_((flat_set<int>::allocator_type()));
+ flat_multiset<int> multiset_((flat_multiset<int>::allocator_type()));
}
//Now test move semantics
{
test_move<flat_set<recursive_flat_set> >();
test_move<flat_multiset<recursive_flat_multiset> >();
}
+ //Now test nth/index_of
+ {
+ flat_set<int> set;
+ flat_multiset<int> mset;
+
+ set.insert(0);
+ set.insert(1);
+ set.insert(2);
+ mset.insert(0);
+ mset.insert(1);
+ mset.insert(2);
+ if(!boost::container::test::test_nth_index_of(set))
+ return 1;
+ if(!boost::container::test::test_nth_index_of(mset))
+ return 1;
+ }
////////////////////////////////////
// Ordered insertion test
@@ -573,16 +590,19 @@ int main()
if(!boost::container::test::test_emplace<flat_multiset<test::EmplaceInt>, SetOptions>())
return 1;
- if(!test_support_for_initialization_list_for<flat_set<int> >())
+ if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<flat_set<int> >())
return 1;
- if(!test_support_for_initialization_list_for<flat_multiset<int> >())
+ if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<flat_multiset<int> >())
return 1;
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<flat_set_propagate_test_wrapper>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_flat_set>())
+ return 1;
+
+ if(!boost::container::test::test_propagate_allocator<boost_container_flat_multiset>())
return 1;
return 0;
diff --git a/libs/container/test/input_from_forward_iterator.hpp b/libs/container/test/input_from_forward_iterator.hpp
index ebc3973a5..9436ceffa 100644
--- a/libs/container/test/input_from_forward_iterator.hpp
+++ b/libs/container/test/input_from_forward_iterator.hpp
@@ -11,7 +11,7 @@
#ifndef BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP
#define BOOST_CONTAINER_TEST_FORWARD_TO_INPUT_ITERATOR_HPP
-#include <iterator>
+#include <boost/container/detail/iterator.hpp>
namespace boost{
namespace container {
@@ -19,11 +19,11 @@ namespace test{
template<class FwdIterator>
class input_iterator_wrapper
- : public std::iterator< std::input_iterator_tag
- , typename std::iterator_traits<FwdIterator>::value_type
- , typename std::iterator_traits<FwdIterator>::difference_type
- , typename std::iterator_traits<FwdIterator>::pointer
- , typename std::iterator_traits<FwdIterator>::reference
+ : public boost::container::iterator< std::input_iterator_tag
+ , typename boost::container::iterator_traits<FwdIterator>::value_type
+ , typename boost::container::iterator_traits<FwdIterator>::difference_type
+ , typename boost::container::iterator_traits<FwdIterator>::pointer
+ , typename boost::container::iterator_traits<FwdIterator>::reference
>
{
FwdIterator m_it;
@@ -46,10 +46,10 @@ class input_iterator_wrapper
//Default destructor...
//~input_iterator_wrapper();
- typename std::iterator_traits<FwdIterator>::reference operator*() const
+ typename boost::container::iterator_traits<FwdIterator>::reference operator*() const
{ return *m_it; }
- typename std::iterator_traits<FwdIterator>::pointer operator->() const
+ typename boost::container::iterator_traits<FwdIterator>::pointer operator->() const
{ return m_it.operator->(); }
input_iterator_wrapper& operator++()
diff --git a/libs/container/test/insert_test.hpp b/libs/container/test/insert_test.hpp
index f29f496ff..cb862f3c5 100644
--- a/libs/container/test/insert_test.hpp
+++ b/libs/container/test/insert_test.hpp
@@ -53,7 +53,8 @@ bool test_range_insertion()
for (std::size_t i = 0; i <= input_deque.size(); ++i)
{
std::deque<int> std_deque;
- SeqContainer seq_container;
+ ::boost::movelib::unique_ptr<SeqContainer> const pseqcontainer = ::boost::movelib::make_unique<SeqContainer>();
+ SeqContainer &seq_container = *pseqcontainer;
for (int element = -10; element < 10; ++element)
{
diff --git a/libs/container/test/insert_vs_emplace_test.cpp b/libs/container/test/insert_vs_emplace_test.cpp
index c523dab46..b91a693c5 100644
--- a/libs/container/test/insert_vs_emplace_test.cpp
+++ b/libs/container/test/insert_vs_emplace_test.cpp
@@ -64,7 +64,7 @@ public:
X& operator=(BOOST_COPY_ASSIGN_REF(X) x)
{
-
+
i_ = x.i_;
p_ = x.p_;
// std::cout << "X& operator=(const X& x)\n";
@@ -72,7 +72,7 @@ public:
return *this;
}
- X(BOOST_RV_REF(X) x) BOOST_CONTAINER_NOEXCEPT
+ X(BOOST_RV_REF(X) x) BOOST_NOEXCEPT_OR_NOTHROW
: i_(x.i_)
, p_(x.p_)
{
@@ -80,9 +80,9 @@ public:
sp.mc++;
}
- X& operator=(BOOST_RV_REF(X) x) BOOST_CONTAINER_NOEXCEPT
+ X& operator=(BOOST_RV_REF(X) x) BOOST_NOEXCEPT_OR_NOTHROW
{
-
+
i_ = x.i_;
p_ = x.p_;
// std::cout << "X& operator=(X&& x)\n";
diff --git a/libs/container/test/list_test.cpp b/libs/container/test/list_test.cpp
index 1c035a74f..84588b798 100644
--- a/libs/container/test/list_test.cpp
+++ b/libs/container/test/list_test.cpp
@@ -53,9 +53,9 @@ template class boost::container::list
namespace container_detail {
-template class iterator
+template class iterator_from_iiterator
<intrusive_list_type< std::allocator<int> >::container_type::iterator, true >;
-template class iterator
+template class iterator_from_iiterator
<intrusive_list_type< std::allocator<int> >::container_type::iterator, false>;
}
@@ -71,7 +71,7 @@ public:
list<recursive_list>::const_iterator cit_;
list<recursive_list>::reverse_iterator rit_;
list<recursive_list>::const_reverse_iterator crit_;
-
+
recursive_list &operator=(const recursive_list &o)
{ list_ = o.list_; return *this; }
};
@@ -126,10 +126,14 @@ bool test_support_for_initializer_list()
const std::initializer_list<int> il = {1, 10};
const list<int> expectedList(il.begin(), il.end());
- const list<int> testConstructor = il;
+ const list<int> testConstructor((il));
if(testConstructor != expectedList)
return false;
+ const list<int> testConstructorAllocator(il, list<int>::allocator_type());
+ if (testConstructorAllocator != expectedList)
+ return false;
+
list<int> testAssignOperator = {10, 11};
testAssignOperator = il;
if(testAssignOperator != expectedList)
@@ -150,6 +154,22 @@ bool test_support_for_initializer_list()
return true;
}
+struct boost_container_list;
+
+namespace boost { namespace container { namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_list>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::list<T, Allocator> type;
+ };
+};
+
+}}} //namespace boost::container::test
+
int main ()
{
recursive_list_test();
@@ -197,7 +217,7 @@ int main ()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<list>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_list>())
return 1;
if(!test_support_for_initializer_list())
@@ -207,3 +227,13 @@ int main ()
}
#include <boost/container/detail/config_end.hpp>
+
+/*
+#include <boost/container/list.hpp>
+//#include <list>
+
+int main()
+{
+ return 0;
+}
+*/
diff --git a/libs/container/test/list_test.hpp b/libs/container/test/list_test.hpp
index 9aae06d9f..aec82c6f3 100644
--- a/libs/container/test/list_test.hpp
+++ b/libs/container/test/list_test.hpp
@@ -12,18 +12,17 @@
#define BOOST_CONTAINER_TEST_LIST_TEST_HEADER
#include <boost/container/detail/config_begin.hpp>
+#include <boost/container/detail/iterator.hpp>
#include "check_equal_containers.hpp"
-#include <memory>
-#include <list>
-#include <vector>
-#include <functional>
#include "print_container.hpp"
#include "input_from_forward_iterator.hpp"
#include <boost/move/utility_core.hpp>
#include <boost/move/iterator.hpp>
-#include <string>
#include <boost/move/make_unique.hpp>
+#include <list>
+#include <functional> //std::greater
+
namespace boost{
namespace container {
namespace test{
@@ -71,6 +70,32 @@ bool list_copyable_only(V1 &boostlist, V2 &stdlist, boost::container::container_
stdlist.push_front(int(3));
if(!test::CheckEqualContainers(boostlist, stdlist)) return false;
}
+ { //List(const List &)
+ ::boost::movelib::unique_ptr<V1> const pv1 = ::boost::movelib::make_unique<V1>(boostlist);
+ ::boost::movelib::unique_ptr<V2> const pv2 = ::boost::movelib::make_unique<V2>(stdlist);
+
+ V1 &v1 = *pv1;
+ V2 &v2 = *pv2;
+
+ boostlist.clear();
+ stdlist.clear();
+ boostlist.assign(v1.begin(), v1.end());
+ stdlist.assign(v2.begin(), v2.end());
+ if(!test::CheckEqualContainers(boostlist, stdlist)) return 1;
+ }
+ { //List(const List &, alloc)
+ ::boost::movelib::unique_ptr<V1> const pv1 = ::boost::movelib::make_unique<V1>(boostlist, typename V1::allocator_type());
+ ::boost::movelib::unique_ptr<V2> const pv2 = ::boost::movelib::make_unique<V2>(stdlist);
+
+ V1 &v1 = *pv1;
+ V2 &v2 = *pv2;
+
+ boostlist.clear();
+ stdlist.clear();
+ boostlist.assign(v1.begin(), v1.end());
+ stdlist.assign(v2.begin(), v2.end());
+ if(!test::CheckEqualContainers(boostlist, stdlist)) return 1;
+ }
return true;
}
@@ -149,6 +174,37 @@ int list_test (bool copied_allocators_equal = true)
const int max = 100;
typedef list_push_data_function<DoublyLinked> push_data_t;
+ { //List(n)
+ ::boost::movelib::unique_ptr<MyBoostList> const pboostlist = ::boost::movelib::make_unique<MyBoostList>(100);
+ ::boost::movelib::unique_ptr<MyStdList> const pstdlist = ::boost::movelib::make_unique<MyStdList>(100);
+ if(!test::CheckEqualContainers(*pboostlist, *pstdlist)) return 1;
+ }
+ { //List(n, alloc)
+ ::boost::movelib::unique_ptr<MyBoostList> const pboostlist = ::boost::movelib::make_unique<MyBoostList>(100, typename MyBoostList::allocator_type());
+ ::boost::movelib::unique_ptr<MyStdList> const pstdlist = ::boost::movelib::make_unique<MyStdList>(100);
+ if(!test::CheckEqualContainers(*pboostlist, *pstdlist)) return 1;
+ }
+ { //List(List &&)
+ ::boost::movelib::unique_ptr<MyStdList> const stdlistp = ::boost::movelib::make_unique<MyStdList>(100);
+ ::boost::movelib::unique_ptr<MyBoostList> const boostlistp = ::boost::movelib::make_unique<MyBoostList>(100);
+ ::boost::movelib::unique_ptr<MyBoostList> const boostlistp2 = ::boost::movelib::make_unique<MyBoostList>(::boost::move(*boostlistp));
+ if(!test::CheckEqualContainers(*boostlistp2, *stdlistp)) return 1;
+ }
+ { //List(List &&, alloc)
+ ::boost::movelib::unique_ptr<MyStdList> const stdlistp = ::boost::movelib::make_unique<MyStdList>(100);
+ ::boost::movelib::unique_ptr<MyBoostList> const boostlistp = ::boost::movelib::make_unique<MyBoostList>(100);
+ ::boost::movelib::unique_ptr<MyBoostList> const boostlistp2 = ::boost::movelib::make_unique<MyBoostList>
+ (::boost::move(*boostlistp), typename MyBoostList::allocator_type());
+ if(!test::CheckEqualContainers(*boostlistp2, *stdlistp)) return 1;
+ }
+ { //List operator=(List &&)
+ ::boost::movelib::unique_ptr<MyStdList> const stdlistp = ::boost::movelib::make_unique<MyStdList>(100);
+ ::boost::movelib::unique_ptr<MyBoostList> const boostlistp = ::boost::movelib::make_unique<MyBoostList>(100);
+ ::boost::movelib::unique_ptr<MyBoostList> const boostlistp2 = ::boost::movelib::make_unique<MyBoostList>();
+ *boostlistp2 = ::boost::move(*boostlistp);
+ if(!test::CheckEqualContainers(*boostlistp2, *stdlistp)) return 1;
+ }
+
::boost::movelib::unique_ptr<MyBoostList> const pboostlist = ::boost::movelib::make_unique<MyBoostList>();
::boost::movelib::unique_ptr<MyStdList> const pstdlist = ::boost::movelib::make_unique<MyStdList>();
@@ -229,7 +285,7 @@ int list_test (bool copied_allocators_equal = true)
boostlist.insert(boostlist.begin()
,boost::make_move_iterator(&aux_vect[0])
,boost::make_move_iterator(&aux_vect[50]));
- if(it_insert != boostlist.begin() || std::distance(it_insert, old_begin) != 50)
+ if(it_insert != boostlist.begin() || boost::container::iterator_distance(it_insert, old_begin) != 50)
return 1;
stdlist.insert(stdlist.begin(), &aux_vect2[0], &aux_vect2[50]);
@@ -249,7 +305,7 @@ int list_test (bool copied_allocators_equal = true)
it_insert = boostlist.insert(boostlist.end()
,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[0]))
,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[50])));
- if(std::distance(it_insert, boostlist.end()) != 50)
+ if(boost::container::iterator_distance(it_insert, boostlist.end()) != 50)
return 1;
stdlist.insert(stdlist.end(), &aux_vect2[0], &aux_vect2[50]);
if(!CheckEqualContainers(boostlist, stdlist))
@@ -285,6 +341,20 @@ int list_test (bool copied_allocators_equal = true)
if(!CheckEqualContainers(boostlist, stdlist))
return 1;
+ //some comparison operators
+ if(!(boostlist == boostlist))
+ return 1;
+ if(boostlist != boostlist)
+ return 1;
+ if(boostlist < boostlist)
+ return 1;
+ if(boostlist > boostlist)
+ return 1;
+ if(!(boostlist <= boostlist))
+ return 1;
+ if(!(boostlist >= boostlist))
+ return 1;
+
if(push_data_t::execute(max, boostlist, stdlist)){
return 1;
}
@@ -340,6 +410,56 @@ int list_test (bool copied_allocators_equal = true)
return 0;
}
+template<class List>
+bool test_list_methods_with_initializer_list_as_argument_for()
+{
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ const std::initializer_list<int> il = {5, 10, 15};
+ const List expected_list(il.begin(), il.end());
+ {
+ List sl = il;
+ if(sl != expected_list)
+ return false;
+ }
+
+ {
+ List sl = {1, 2};
+ sl = il;
+ if(sl != expected_list)
+ return false;
+ }
+ {
+ List sl({ 1, 2 }, typename List::allocator_type());
+ sl = il;
+ if (sl != expected_list)
+ return false;
+ }
+ {
+ List sl = {4, 5};
+ sl.assign(il);
+ if(sl != expected_list)
+ return false;
+ }
+
+ {
+ List sl = {15};
+ sl.insert(sl.cbegin(), {5, 10});
+ if(sl != expected_list)
+ return false;
+ }
+
+ {
+ List sl = {5};
+ sl.insert_after(sl.cbegin(), {10, 15});
+ if(sl != expected_list)
+ return false;
+ }
+ return true;
+#endif
+ return true;
+}
+
+
} //namespace test{
} //namespace container {
} //namespace boost{
diff --git a/libs/container/test/map_test.cpp b/libs/container/test/map_test.cpp
index 505555f19..ebd1eaba1 100644
--- a/libs/container/test/map_test.cpp
+++ b/libs/container/test/map_test.cpp
@@ -12,7 +12,8 @@
#include <boost/container/allocator.hpp>
#include <boost/container/node_allocator.hpp>
#include <boost/container/adaptive_pool.hpp>
-#include <utility>
+
+#include <map>
#include "print_container.hpp"
#include "movable_int.hpp"
@@ -199,7 +200,7 @@ class recursive_map
map<recursive_map, recursive_map>::const_iterator cit_;
map<recursive_map, recursive_map>::reverse_iterator rit_;
map<recursive_map, recursive_map>::const_reverse_iterator crit_;
-
+
friend bool operator< (const recursive_map &a, const recursive_map &b)
{ return a.id_ < b.id_; }
};
@@ -216,7 +217,7 @@ class recursive_multimap
multimap<recursive_multimap, recursive_multimap>::const_iterator cit_;
multimap<recursive_multimap, recursive_multimap>::reverse_iterator rit_;
multimap<recursive_multimap, recursive_multimap>::const_reverse_iterator crit_;
-
+
friend bool operator< (const recursive_multimap &a, const recursive_multimap &b)
{ return a.id_ < b.id_; }
};
@@ -234,45 +235,6 @@ void test_move()
move_assign.swap(original);
}
-template<class T, class A>
-class map_propagate_test_wrapper
- : public boost::container::map
- < T, T, std::less<T>
- , typename boost::container::allocator_traits<A>::template
- portable_rebind_alloc< std::pair<const T, T> >::type
- //tree_assoc_defaults
- >
-{
- BOOST_COPYABLE_AND_MOVABLE(map_propagate_test_wrapper)
- typedef boost::container::map
- < T, T, std::less<T>
- , typename boost::container::allocator_traits<A>::template
- portable_rebind_alloc< std::pair<const T, T> >::type
- > Base;
- public:
- map_propagate_test_wrapper()
- : Base()
- {}
-
- map_propagate_test_wrapper(const map_propagate_test_wrapper &x)
- : Base(x)
- {}
-
- map_propagate_test_wrapper(BOOST_RV_REF(map_propagate_test_wrapper) x)
- : Base(boost::move(static_cast<Base&>(x)))
- {}
-
- map_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(map_propagate_test_wrapper) x)
- { this->Base::operator=(x); return *this; }
-
- map_propagate_test_wrapper &operator=(BOOST_RV_REF(map_propagate_test_wrapper) x)
- { this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
-
- void swap(map_propagate_test_wrapper &x)
- { this->Base::swap(x); }
-};
-
-
template<class VoidAllocator, boost::container::tree_type_enum tree_type_value>
struct GetAllocatorMap
{
@@ -356,37 +318,36 @@ int test_map_variants()
return 0;
}
-template<typename MapType>
-bool test_support_for_initialization_list_for()
+struct boost_container_map;
+struct boost_container_multimap;
+
+namespace boost { namespace container { namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_map>
{
-#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
- const std::initializer_list<std::pair<const int, int>> il
- = {std::make_pair(1, 2), std::make_pair(3, 4)};
- const MapType expected(il.begin(), il.end());
+ template <class T, class Allocator>
+ struct apply
{
- const MapType sil = il;
- if (sil != expected)
- return false;
-
- const MapType sil_ordered(ordered_unique_range, il);
- if(sil_ordered != expected)
- return false;
-
- MapType sil_assign = {std::make_pair(99, 100)};
- sil_assign = il;
- if(sil_assign != expected)
- return false;
- }
+ typedef typename boost::container::allocator_traits<Allocator>::
+ template portable_rebind_alloc<std::pair<const T, T> >::type TypeAllocator;
+ typedef boost::container::map<T, T, std::less<T>, TypeAllocator> type;
+ };
+};
+
+template<>
+struct alloc_propagate_base<boost_container_multimap>
+{
+ template <class T, class Allocator>
+ struct apply
{
- MapType sil;
- sil.insert(il);
- if(sil != expected)
- return false;
- }
- return true;
-#endif
- return true;
-}
+ typedef typename boost::container::allocator_traits<Allocator>::
+ template portable_rebind_alloc<std::pair<const T, T> >::type TypeAllocator;
+ typedef boost::container::multimap<T, T, std::less<T>, TypeAllocator> type;
+ };
+};
+
+}}} //namespace boost::container::test
int main ()
{
@@ -397,8 +358,8 @@ int main ()
}
//Allocator argument container
{
- map<int, int> map_((std::allocator<std::pair<const int, int> >()));
- multimap<int, int> multimap_((std::allocator<std::pair<const int, int> >()));
+ map<int, int> map_((map<int, int>::allocator_type()));
+ multimap<int, int> multimap_((multimap<int, int>::allocator_type()));
}
//Now test move semantics
{
@@ -461,13 +422,16 @@ int main ()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<map_propagate_test_wrapper>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_map>())
+ return 1;
+
+ if(!boost::container::test::test_propagate_allocator<boost_container_multimap>())
return 1;
- if(!test_support_for_initialization_list_for<map<int, int> >())
+ if (!boost::container::test::test_map_support_for_initialization_list_for<map<int, int> >())
return 1;
- if(!test_support_for_initialization_list_for<multimap<int, int> >())
+ if (!boost::container::test::test_map_support_for_initialization_list_for<multimap<int, int> >())
return 1;
////////////////////////////////////
diff --git a/libs/container/test/map_test.hpp b/libs/container/test/map_test.hpp
index 83f1cfbf5..79504d998 100644
--- a/libs/container/test/map_test.hpp
+++ b/libs/container/test/map_test.hpp
@@ -13,23 +13,23 @@
#include <boost/container/detail/config_begin.hpp>
#include "check_equal_containers.hpp"
-#include <map>
-#include <functional>
-#include <utility>
#include "print_container.hpp"
-#include <boost/container/detail/utilities.hpp>
#include <boost/container/detail/pair.hpp>
#include <boost/move/iterator.hpp>
#include <boost/move/utility_core.hpp>
#include <boost/move/make_unique.hpp>
+
+#include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
#include <string>
+#include <iostream>
+
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost { namespace container { namespace test {
-#include <boost/intrusive/detail/has_member_function_callable_with.hpp>
-#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME rebalance
-#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace test {
-#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
-#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, <boost/intrusive/detail/has_member_function_callable_with.hpp>))
-#include BOOST_PP_ITERATE()
+BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(has_member_rebalance, rebalance)
+
+}}}
template<class T1, class T2, class T3, class T4>
bool operator ==(std::pair<T1, T2> &p1, std::pair<T1, T2> &p2)
@@ -133,6 +133,80 @@ int map_test()
typedef container_detail::pair<IntType, IntType> IntPairType;
typedef typename MyStdMap::value_type StdPairType;
const int max = 50;
+ typedef typename MyStdMap::value_type StdValueType;
+ typedef typename MyStdMap::key_type StdKeyType;
+ typedef typename MyStdMap::mapped_type StdMappedType;
+
+
+ //Test construction from a range
+ {
+ IntPairType aux_vect[50];
+ for(int i = 0; i < 50; ++i){
+ IntType i1(i/2);
+ IntType i2(i/2);
+ new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
+ }
+
+ StdValueType aux_vect2[50];
+ for(int i = 0; i < 50; ++i){
+ new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2));
+ }
+
+ IntPairType aux_vect3[50];
+ for(int i = 0; i < 50; ++i){
+ IntType i1(i/2);
+ IntType i2(i/2);
+ new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
+ }
+
+ ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>
+ ( boost::make_move_iterator(&aux_vect[0])
+ , boost::make_move_iterator(&aux_vect[0] + 50), typename MyBoostMap::key_compare());
+ ::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>
+ (&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
+ if(!CheckEqualContainers(*pboostmap, *pstdmap)) return 1;
+
+ ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>
+ ( boost::make_move_iterator(&aux_vect3[0])
+ , boost::make_move_iterator(&aux_vect3[0] + 50), typename MyBoostMap::key_compare());
+ ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>
+ (&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
+ if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1;
+ }
+ {
+ IntPairType aux_vect[50];
+ for(int i = 0; i < 50; ++i){
+ IntType i1(i/2);
+ IntType i2(i/2);
+ new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2));
+ }
+
+ StdValueType aux_vect2[50];
+ for(int i = 0; i < 50; ++i){
+ new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2));
+ }
+
+ IntPairType aux_vect3[50];
+ for(int i = 0; i < 50; ++i){
+ IntType i1(i/2);
+ IntType i2(i/2);
+ new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2));
+ }
+
+ ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>
+ ( boost::make_move_iterator(&aux_vect[0])
+ , boost::make_move_iterator(&aux_vect[0] + 50), typename MyBoostMap::allocator_type());
+ ::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>
+ (&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
+ if(!CheckEqualContainers(*pboostmap, *pstdmap)) return 1;
+
+ ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>
+ ( boost::make_move_iterator(&aux_vect3[0])
+ , boost::make_move_iterator(&aux_vect3[0] + 50), typename MyBoostMap::allocator_type());
+ ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>
+ (&aux_vect2[0], &aux_vect2[0] + 50, typename MyStdMap::key_compare());
+ if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1;
+ }
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>();
::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>();
@@ -143,7 +217,6 @@ int map_test()
MyBoostMultiMap &boostmultimap = *pboostmultimap;
MyStdMultiMap &stdmultimap = *pstdmultimap;
- //Test construction from a range
{
//This is really nasty, but we have no other simple choice
IntPairType aux_vect[50];
@@ -206,6 +279,20 @@ int map_test()
if(!CheckEqualContainers(boostmap2, stdmap2)) return 1;
if(!CheckEqualContainers(boostmultimap2, stdmultimap2)) return 1;
+ //some comparison operators
+ if(!(boostmap2 == boostmap2))
+ return 1;
+ if(boostmap2 != boostmap2)
+ return 1;
+ if(boostmap2 < boostmap2)
+ return 1;
+ if(boostmap2 > boostmap2)
+ return 1;
+ if(!(boostmap2 <= boostmap2))
+ return 1;
+ if(!(boostmap2 >= boostmap2))
+ return 1;
+
::boost::movelib::unique_ptr<MyBoostMap> const pboostmap3 = ::boost::movelib::make_unique<MyBoostMap>
( boost::make_move_iterator(&aux_vect[0])
, boost::make_move_iterator(&aux_vect[0] + 50));
@@ -492,8 +579,8 @@ int map_test()
std::pair<typename MyStdMultiMap::iterator, typename MyStdMultiMap::iterator> sret =
stdmultimap.equal_range(stdmultimap.begin()->first);
- if( std::distance(bret.first, bret.second) !=
- std::distance(sret.first, sret.second) ){
+ if( boost::container::iterator_distance(bret.first, bret.second) !=
+ boost::container::iterator_distance(sret.first, sret.second) ){
return 1;
}
}
@@ -520,13 +607,13 @@ int map_test()
return 1;
map_test_rebalanceable(boostmap
- , container_detail::bool_<has_member_function_callable_with_rebalance<MyBoostMap>::value>());
+ , container_detail::bool_<has_member_rebalance<MyBoostMap>::value>());
if(!CheckEqualContainers(boostmap, stdmap)){
std::cout << "Error in boostmap.rebalance()" << std::endl;
return 1;
}
map_test_rebalanceable(boostmultimap
- , container_detail::bool_<has_member_function_callable_with_rebalance<MyBoostMultiMap>::value>());
+ , container_detail::bool_<has_member_rebalance<MyBoostMap>::value>());
if(!CheckEqualContainers(boostmultimap, stdmultimap)){
std::cout << "Error in boostmultimap.rebalance()" << std::endl;
return 1;
@@ -577,6 +664,48 @@ int map_test()
return 0;
}
+template<typename MapType>
+bool test_map_support_for_initialization_list_for()
+{
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ const std::initializer_list<std::pair<typename MapType::value_type::first_type, typename MapType::mapped_type>> il
+ = { std::make_pair(1, 2), std::make_pair(3, 4) };
+
+ const MapType expected(il.begin(), il.end());
+ {
+ const MapType sil = il;
+ if (sil != expected)
+ return false;
+
+ MapType sila(il, typename MapType::allocator_type());
+ if (sila != expected)
+ return false;
+
+ MapType silca(il, typename MapType::key_compare(), typename MapType::allocator_type());
+ if (silca != expected)
+ return false;
+
+ const MapType sil_ordered(ordered_unique_range, il);
+ if (sil_ordered != expected)
+ return false;
+
+ MapType sil_assign = { std::make_pair(99, 100) };
+ sil_assign = il;
+ if (sil_assign != expected)
+ return false;
+ }
+ {
+ MapType sil;
+ sil.insert(il);
+ if (sil != expected)
+ return false;
+ }
+ return true;
+#endif
+ return true;
+}
+
+
} //namespace test{
} //namespace container {
} //namespace boost{
diff --git a/libs/container/test/null_iterators_test.cpp b/libs/container/test/null_iterators_test.cpp
index 7bf4b8199..faf60be13 100644
--- a/libs/container/test/null_iterators_test.cpp
+++ b/libs/container/test/null_iterators_test.cpp
@@ -19,17 +19,16 @@
#include <boost/container/set.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/flat_map.hpp>
-#include <boost/intrusive/detail/memory_util.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
#include <boost/core/lightweight_test.hpp>
-#include <boost/aligned_storage.hpp>
#include <boost/static_assert.hpp>
#include <cstring>
#include <new>
using namespace boost::container;
-typedef boost::aligned_storage<sizeof(void*)*4>::type buffer_t;
+typedef boost::container::container_detail::aligned_storage<sizeof(void*)*4>::type buffer_t;
static buffer_t buffer_0x00;
static buffer_t buffer_0xFF;
diff --git a/libs/container/test/print_container.hpp b/libs/container/test/print_container.hpp
index afc07f69a..2e49ec60e 100644
--- a/libs/container/test/print_container.hpp
+++ b/libs/container/test/print_container.hpp
@@ -12,33 +12,12 @@
#define BOOST_PRINTCONTAINER_HPP
#include <boost/container/detail/config_begin.hpp>
-#include <functional>
#include <iostream>
-#include <algorithm>
namespace boost{
namespace container {
namespace test{
-struct PrintValues
-{
- typedef int argument_type;
- typedef void result_type;
-
- void operator() (int value) const
- {
- std::cout << value << " ";
- }
-};
-
-template<class Container>
-void PrintContents(const Container &cont, const char *contName)
-{
- std::cout<< "Printing contents of " << contName << std::endl;
- std::for_each(cont.begin(), cont.end(), PrintValues());
- std::cout<< std::endl << std::endl;
-}
-
//Function to dump data
template<class MyBoostCont
,class MyStdCont>
diff --git a/libs/container/test/propagate_allocator_test.hpp b/libs/container/test/propagate_allocator_test.hpp
index 67138892b..aefda7658 100644
--- a/libs/container/test/propagate_allocator_test.hpp
+++ b/libs/container/test/propagate_allocator_test.hpp
@@ -20,81 +20,193 @@ namespace boost{
namespace container {
namespace test{
-template<template<class, class> class ContainerWrapper>
-bool test_propagate_allocator()
+template<class Selector>
+struct alloc_propagate_base;
+
+template<class T, class Allocator, class Selector>
+class alloc_propagate_wrapper
+ : public alloc_propagate_base<Selector>::template apply<T, Allocator>::type
{
- {
- typedef propagation_test_allocator<char, true, true, true, true> AlwaysPropagate;
- typedef ContainerWrapper<char, AlwaysPropagate> PropagateCont;
+ BOOST_COPYABLE_AND_MOVABLE(alloc_propagate_wrapper)
- //////////////////////////////////////////
- //Test AlwaysPropagate allocator propagation
- //////////////////////////////////////////
- AlwaysPropagate::reset_unique_id();
+ public:
+ typedef typename alloc_propagate_base
+ <Selector>::template apply<T, Allocator>::type Base;
- //default constructor
- PropagateCont c;
- BOOST_TEST (c.get_stored_allocator().id_ == 0);
- BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
- BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
- BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
- BOOST_TEST (c.get_stored_allocator().assign_moves_ == 0);
- BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
+ typedef typename Base::allocator_type allocator_type;
+ typedef typename Base::value_type value_type;
+ typedef typename Base::size_type size_type;
- //copy constructor
- PropagateCont c2(c);
- //propagate_on_copy_constructor produces copies, moves or RVO (depending on the compiler).
- //For allocators that copy in select_on_container_copy_construction, at least we must have a copy
- unsigned int ctr_copies = c2.get_stored_allocator().ctr_copies_;
- unsigned int ctr_moves = c2.get_stored_allocator().ctr_moves_;
- BOOST_TEST (c2.get_stored_allocator().id_ == 0);
- BOOST_TEST (ctr_copies > 0);
- BOOST_TEST (c2.get_stored_allocator().ctr_moves_ >= 0);
- BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
- BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
- BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ alloc_propagate_wrapper()
+ : Base()
+ {}
- //move constructor
- PropagateCont c3(boost::move(c2));
- BOOST_TEST (c3.get_stored_allocator().id_ == 0);
- BOOST_TEST (c3.get_stored_allocator().ctr_copies_ == ctr_copies);
- BOOST_TEST (c3.get_stored_allocator().ctr_moves_ > ctr_moves);
- ctr_moves = c3.get_stored_allocator().ctr_moves_;
- BOOST_TEST (ctr_moves > 0);
- BOOST_TEST (c3.get_stored_allocator().assign_copies_ == 0);
- BOOST_TEST (c3.get_stored_allocator().assign_moves_ == 0);
- BOOST_TEST (c3.get_stored_allocator().swaps_ == 0);
-
- //copy assign
- c2 = c3;
- unsigned int assign_copies = c2.get_stored_allocator().assign_copies_;
- BOOST_TEST (c2.get_stored_allocator().id_ == 0);
- BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == ctr_copies);
- BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == ctr_moves);
- BOOST_TEST (assign_copies == 1);
- BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
- BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ explicit alloc_propagate_wrapper(const allocator_type &a)
+ : Base(a)
+ {}
+/*
+ //sequence containers only
+ explicit alloc_propagate_wrapper(size_type n, const value_type &v, const allocator_type &a)
+ : Base(n, v, a)
+ {}
- //move assign
- c = boost::move(c2);
- unsigned int assign_moves = c.get_stored_allocator().assign_moves_;
- BOOST_TEST (c.get_stored_allocator().id_ == 0);
- BOOST_TEST (c.get_stored_allocator().ctr_copies_ == ctr_copies);
- BOOST_TEST (c.get_stored_allocator().ctr_moves_ == ctr_moves);
- BOOST_TEST (c.get_stored_allocator().assign_copies_ == assign_copies);
- BOOST_TEST (assign_moves == 1);
- BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
+ alloc_propagate_wrapper(size_type n, const allocator_type &a)
+ : Base(n, a)
+ {}*/
+
+ template<class Iterator>
+ alloc_propagate_wrapper(Iterator b, Iterator e, const allocator_type &a)
+ : Base(b, e, a)
+ {}
+
+ #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ alloc_propagate_wrapper(std::initializer_list<value_type> il, const allocator_type& a)
+ : Base(il, a)
+ {}
+/*
+ //associative containers only
+ alloc_propagate_wrapper(std::initializer_list<value_type> il, const Compare& comp, const allocator_type& a)
+ : Base(il, comp, a)
+ {}*/
+
+ #endif
+
+ alloc_propagate_wrapper(const alloc_propagate_wrapper &x)
+ : Base(x)
+ {}
+
+ alloc_propagate_wrapper(const alloc_propagate_wrapper &x, const allocator_type &a)
+ : Base(x, a)
+ {}
+
+ alloc_propagate_wrapper(BOOST_RV_REF(alloc_propagate_wrapper) x)
+ : Base(boost::move(static_cast<Base&>(x)))
+ {}
+
+ alloc_propagate_wrapper(BOOST_RV_REF(alloc_propagate_wrapper) x, const allocator_type &a)
+ : Base(boost::move(static_cast<Base&>(x)), a)
+ {}
+
+ alloc_propagate_wrapper &operator=(BOOST_COPY_ASSIGN_REF(alloc_propagate_wrapper) x)
+ { this->Base::operator=(x); return *this; }
+
+ alloc_propagate_wrapper &operator=(BOOST_RV_REF(alloc_propagate_wrapper) x)
+ { this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
+
+ void swap(alloc_propagate_wrapper &x)
+ { this->Base::swap(x); }
+};
+
+template<class T>
+struct get_real_stored_allocator
+{
+ typedef typename T::stored_allocator_type type;
+};
+
+template<class Container>
+void test_propagate_allocator_allocator_arg();
- //swap
- c.get_stored_allocator().id_ = 999;
- c.swap(c2);
- unsigned int swaps = c2.get_stored_allocator().swaps_;
- BOOST_TEST (c2.get_stored_allocator().id_ == 999);
- BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == ctr_copies);
- BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == ctr_moves);
- BOOST_TEST (c2.get_stored_allocator().assign_copies_ == assign_copies);
- BOOST_TEST (c2.get_stored_allocator().assign_moves_ == assign_moves);
- BOOST_TEST (swaps == 1);
+template<class Selector>
+bool test_propagate_allocator()
+{
+ {
+ typedef propagation_test_allocator<char, true, true, true, true> AlwaysPropagate;
+ typedef alloc_propagate_wrapper<char, AlwaysPropagate, Selector> PropagateCont;
+ typedef typename get_real_stored_allocator<typename PropagateCont::Base>::type StoredAllocator;
+ {
+ //////////////////////////////////////////
+ //Test AlwaysPropagate allocator propagation
+ //////////////////////////////////////////
+
+ //default constructor
+ StoredAllocator::reset_unique_id(111);
+ PropagateCont c; //stored 112
+ BOOST_TEST (c.get_stored_allocator().id_ == 112);
+ BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //copy constructor
+ StoredAllocator::reset_unique_id(222);
+ PropagateCont c; //stored 223
+ BOOST_TEST (c.get_stored_allocator().id_ == 223);
+ //propagate_on_copy_constructor produces copies, moves or RVO (depending on the compiler).
+ //For allocators that copy in select_on_container_copy_construction, at least we must have a copy
+ PropagateCont c2(c); //should propagate 223
+ BOOST_TEST (c2.get_stored_allocator().id_ == 223);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ >= 1);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ >= 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //move constructor
+ StoredAllocator::reset_unique_id(333);
+ PropagateCont c; //stored 334
+ BOOST_TEST (c.get_stored_allocator().id_ == 334);
+ PropagateCont c2(boost::move(c)); //should propagate 334
+ BOOST_TEST (c2.get_stored_allocator().id_ == 334);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ > 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //copy assign
+ StoredAllocator::reset_unique_id(444);
+ PropagateCont c; //stored 445
+ BOOST_TEST (c.get_stored_allocator().id_ == 445);
+ PropagateCont c2; //stored 446
+ BOOST_TEST (c2.get_stored_allocator().id_ == 446);
+ c2 = c; //should propagate 445
+ BOOST_TEST (c2.get_stored_allocator().id_ == 445);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 1);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //move assign
+ StoredAllocator::reset_unique_id(555);
+ PropagateCont c; //stored 556
+ BOOST_TEST (c.get_stored_allocator().id_ == 556);
+ PropagateCont c2; //stored 557
+ BOOST_TEST (c2.get_stored_allocator().id_ == 557);
+ c = boost::move(c2); //should propagate 557
+ BOOST_TEST (c.get_stored_allocator().id_ == 557);
+ BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_moves_ == 1);
+ BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //swap
+ StoredAllocator::reset_unique_id(666);
+ PropagateCont c; //stored 667
+ BOOST_TEST (c.get_stored_allocator().id_ == 667);
+ PropagateCont c2; //stored 668
+ BOOST_TEST (c2.get_stored_allocator().id_ == 668);
+ c.swap(c2);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 1);
+ BOOST_TEST (c.get_stored_allocator().swaps_ == 1);
+ }
+ //And now allocator argument constructors
+ test_propagate_allocator_allocator_arg<PropagateCont>();
}
//////////////////////////////////////////
@@ -102,74 +214,149 @@ bool test_propagate_allocator()
//////////////////////////////////////////
{
typedef propagation_test_allocator<char, false, false, false, false> NeverPropagate;
- typedef ContainerWrapper<char, NeverPropagate> NoPropagateCont;
- NeverPropagate::reset_unique_id();
+ typedef alloc_propagate_wrapper<char, NeverPropagate, Selector> NoPropagateCont;
+ typedef typename get_real_stored_allocator<typename NoPropagateCont::Base>::type StoredAllocator;
+ {
+ //default constructor
+ StoredAllocator::reset_unique_id(111);
+ NoPropagateCont c; //stored 112
+ BOOST_TEST (c.get_stored_allocator().id_ == 112);
+ BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //copy constructor
+ //propagate_on_copy_constructor produces copies, moves or RVO (depending on the compiler)
+ //For allocators that don't copy in select_on_container_copy_construction we must have a default
+ //construction
+ StoredAllocator::reset_unique_id(222);
+ NoPropagateCont c; //stored 223
+ BOOST_TEST (c.get_stored_allocator().id_ == 223);
+ NoPropagateCont c2(c); //should NOT propagate 223
+ BOOST_TEST (c2.get_stored_allocator().id_ == 224);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ >= 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ >= 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //move constructor
+ StoredAllocator::reset_unique_id(333);
+ NoPropagateCont c; //stored 334
+ BOOST_TEST (c.get_stored_allocator().id_ == 334);
+ NoPropagateCont c2(boost::move(c)); // should NOT propagate 334
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ >= 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ >= 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //copy assign
+ StoredAllocator::reset_unique_id(444);
+ NoPropagateCont c; //stored 445
+ NoPropagateCont c2; //stored 446
+ c2 = c; // should NOT propagate 445
+ BOOST_TEST (c2.get_stored_allocator().id_ == 446);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //move assign
+ StoredAllocator::reset_unique_id(555);
+ NoPropagateCont c; //stored 556
+ NoPropagateCont c2; //stored 557
+ c2 = c; // should NOT propagate 556
+ BOOST_TEST (c2.get_stored_allocator().id_ == 557);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ }
+ {
+ //swap
+ StoredAllocator::reset_unique_id(666);
+ NoPropagateCont c; //stored 667
+ BOOST_TEST (c.get_stored_allocator().id_ == 667);
+ NoPropagateCont c2; //stored 668
+ BOOST_TEST (c2.get_stored_allocator().id_ == 668);
+ c2.swap(c); // should NOT swap 667 and 668
+ BOOST_TEST (c2.get_stored_allocator().id_ == 668);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
+ BOOST_TEST (c.get_stored_allocator().id_ == 667);
+ BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
+ BOOST_TEST (c.get_stored_allocator().assign_moves_ == 0);
+ BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
+ }
+ //And now allocator argument constructors
+ test_propagate_allocator_allocator_arg<NoPropagateCont>();
+ }
- //default constructor
- NoPropagateCont c;
- BOOST_TEST (c.get_stored_allocator().id_ == 0);
- BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
+ return report_errors() == 0;
+}
+
+template<class Container>
+void test_propagate_allocator_allocator_arg()
+{
+ typedef typename Container::allocator_type allocator_type;
+ typedef typename get_real_stored_allocator<typename Container::Base>::type StoredAllocator;
+
+ { //The allocator must be always propagated
+ //allocator constructor
+ allocator_type::reset_unique_id(111);
+ const allocator_type & a = allocator_type(); //stored 112
+ Container c(a); //should propagate 112
+ BOOST_TEST (c.get_stored_allocator().id_ == 112);
+ BOOST_TEST (c.get_stored_allocator().ctr_copies_ > 0);
BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
BOOST_TEST (c.get_stored_allocator().assign_moves_ == 0);
BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
-
- //copy constructor
- //propagate_on_copy_constructor produces copies, moves or RVO (depending on the compiler)
- //For allocators that don't copy in select_on_container_copy_construction we must have a default
- //construction
- NoPropagateCont c2(c);
- unsigned int ctr_copies = c2.get_stored_allocator().ctr_copies_;
- unsigned int ctr_moves = c2.get_stored_allocator().ctr_moves_;
- BOOST_TEST (c2.get_stored_allocator().id_ == 1);
- BOOST_TEST (ctr_copies >= 0);
- BOOST_TEST (ctr_moves >= 0);
- BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
- BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
- BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
-
- //move constructor
- NoPropagateCont c3(boost::move(c2));
- BOOST_TEST (c3.get_stored_allocator().id_ == 1);
- BOOST_TEST (c3.get_stored_allocator().ctr_copies_ == ctr_copies);
- BOOST_TEST (c3.get_stored_allocator().ctr_moves_ > ctr_moves);
- unsigned int ctr_moves2 = ctr_moves;
- ctr_moves = c3.get_stored_allocator().ctr_moves_;
- BOOST_TEST (c3.get_stored_allocator().assign_copies_ == 0);
- BOOST_TEST (c3.get_stored_allocator().assign_moves_ == 0);
- BOOST_TEST (c3.get_stored_allocator().swaps_ == 0);
-
- //copy assign
- c2 = c3;
- BOOST_TEST (c2.get_stored_allocator().id_ == 1);
- BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == ctr_copies);
- BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == ctr_moves2);
+ }
+ {
+ //copy allocator constructor
+ StoredAllocator::reset_unique_id(999);
+ Container c;
+ //stored_allocator_type could be the same type as allocator_type
+ //so reset it again to get a predictable result
+ allocator_type::reset_unique_id(222);
+ Container c2(c, allocator_type()); //should propagate 223
+ BOOST_TEST (c2.get_stored_allocator().id_ == 223);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ > 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == 0);
BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
-
- //move assign
- c = boost::move(c2);
- BOOST_TEST (c.get_stored_allocator().id_ == 0);
- BOOST_TEST (c.get_stored_allocator().ctr_copies_ == 0);
- BOOST_TEST (c.get_stored_allocator().ctr_moves_ == 0);
- BOOST_TEST (c.get_stored_allocator().assign_copies_ == 0);
- BOOST_TEST (c.get_stored_allocator().assign_moves_ == 0);
- BOOST_TEST (c.get_stored_allocator().swaps_ == 0);
-
- //swap
- c.get_stored_allocator().id_ = 999;
- c2.swap(c);
- BOOST_TEST (c2.get_stored_allocator().id_ == 1);
- BOOST_TEST (c.get_stored_allocator().id_ == 999);
- BOOST_TEST (c2.get_stored_allocator().ctr_copies_ == ctr_copies);
- BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == ctr_moves2);
+ }
+ {
+ //move allocator constructor
+ StoredAllocator::reset_unique_id(999);
+ Container c;
+ //stored_allocator_type could be the same type as allocator_type
+ //so reset it again to get a predictable result
+ allocator_type::reset_unique_id(333);
+ Container c2(boost::move(c), allocator_type()); //should propagate 334
+ BOOST_TEST (c2.get_stored_allocator().id_ == 334);
+ BOOST_TEST (c2.get_stored_allocator().ctr_copies_ > 0);
+ BOOST_TEST (c2.get_stored_allocator().ctr_moves_ == 0);
BOOST_TEST (c2.get_stored_allocator().assign_copies_ == 0);
BOOST_TEST (c2.get_stored_allocator().assign_moves_ == 0);
BOOST_TEST (c2.get_stored_allocator().swaps_ == 0);
}
-
- return report_errors() == 0;
}
} //namespace test{
diff --git a/libs/container/test/scoped_allocator_adaptor_test.cpp b/libs/container/test/scoped_allocator_adaptor_test.cpp
index dadeba66b..04b7f8103 100644
--- a/libs/container/test/scoped_allocator_adaptor_test.cpp
+++ b/libs/container/test/scoped_allocator_adaptor_test.cpp
@@ -9,15 +9,19 @@
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/scoped_allocator_fwd.hpp>
-#include <boost/container/detail/utilities.hpp>
-#include <cstddef>
+
+// container/detail
#include <boost/container/detail/mpl.hpp>
+// move
#include <boost/move/utility_core.hpp>
+#include <boost/move/adl_move_swap.hpp>
+// std
#include <memory>
+#include <cstddef>
using namespace boost::container;
-template<class T, unsigned int Id, bool Propagate = false>
+template<class T, unsigned int Id, bool HasTrueTypes = false>
class test_allocator
{
BOOST_COPYABLE_AND_MOVABLE(test_allocator)
@@ -26,12 +30,13 @@ class test_allocator
template<class U>
struct rebind
{
- typedef test_allocator<U, Id, Propagate> other;
+ typedef test_allocator<U, Id, HasTrueTypes> other;
};
- typedef container_detail::bool_<Propagate> propagate_on_container_copy_assignment;
- typedef container_detail::bool_<Propagate> propagate_on_container_move_assignment;
- typedef container_detail::bool_<Propagate> propagate_on_container_swap;
+ typedef container_detail::bool_<HasTrueTypes> propagate_on_container_copy_assignment;
+ typedef container_detail::bool_<HasTrueTypes> propagate_on_container_move_assignment;
+ typedef container_detail::bool_<HasTrueTypes> propagate_on_container_swap;
+ typedef container_detail::bool_<HasTrueTypes> is_always_equal;
typedef T value_type;
test_allocator()
@@ -47,12 +52,12 @@ class test_allocator
{}
template<class U>
- test_allocator(BOOST_RV_REF_BEG test_allocator<U, Id, Propagate> BOOST_RV_REF_END)
+ test_allocator(BOOST_RV_REF_BEG test_allocator<U, Id, HasTrueTypes> BOOST_RV_REF_END)
: m_move_contructed(true), m_move_assigned(false)
{}
template<class U>
- test_allocator(const test_allocator<U, Id, Propagate> &)
+ test_allocator(const test_allocator<U, Id, HasTrueTypes> &)
{}
test_allocator & operator=(BOOST_COPY_ASSIGN_REF(test_allocator))
@@ -79,14 +84,14 @@ class test_allocator
bool m_move_assigned;
};
-template <class T1, class T2, unsigned int Id, bool Propagate>
-bool operator==( const test_allocator<T1, Id, Propagate>&
- , const test_allocator<T2, Id, Propagate>&)
+template <class T1, class T2, unsigned int Id, bool HasTrueTypes>
+bool operator==( const test_allocator<T1, Id, HasTrueTypes>&
+ , const test_allocator<T2, Id, HasTrueTypes>&)
{ return true; }
-template <class T1, class T2, unsigned int Id, bool Propagate>
-bool operator!=( const test_allocator<T1, Id, Propagate>&
- , const test_allocator<T2, Id, Propagate>&)
+template <class T1, class T2, unsigned int Id, bool HasTrueTypes>
+bool operator!=( const test_allocator<T1, Id, HasTrueTypes>&
+ , const test_allocator<T2, Id, HasTrueTypes>&)
{ return false; }
@@ -236,21 +241,22 @@ namespace container {
template<unsigned int AllocatorTag>
struct constructible_with_allocator_prefix
< ::mark_on_scoped_allocation<ConstructiblePrefix, AllocatorTag> >
- : ::boost::true_type
-{};
+{
+ static const bool value = true;
+};
template<unsigned int AllocatorTag>
struct constructible_with_allocator_suffix
< ::mark_on_scoped_allocation<ConstructibleSuffix, AllocatorTag> >
- : ::boost::true_type
-{};
+{
+ static const bool value = true;
+};
} //namespace container {
} //namespace boost {
#include <boost/container/scoped_allocator.hpp>
-#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>
#include <boost/container/vector.hpp>
#include <boost/container/detail/pair.hpp>
@@ -264,12 +270,12 @@ int main()
typedef test_allocator<tagged_integer<2>, 2> InnerAlloc2;
typedef test_allocator<tagged_integer<1>, 11> Inner11IdAlloc1;
- typedef test_allocator<tagged_integer<0>, 0, false> OuterAllocFalsePropagate;
- typedef test_allocator<tagged_integer<0>, 0, true> OuterAllocTruePropagate;
- typedef test_allocator<tagged_integer<1>, 1, false> InnerAlloc1FalsePropagate;
- typedef test_allocator<tagged_integer<1>, 1, true> InnerAlloc1TruePropagate;
- typedef test_allocator<tagged_integer<2>, 2, false> InnerAlloc2FalsePropagate;
- typedef test_allocator<tagged_integer<2>, 2, true> InnerAlloc2TruePropagate;
+ typedef test_allocator<tagged_integer<0>, 0, false> OuterAllocFalseHasTrueTypes;
+ typedef test_allocator<tagged_integer<0>, 0, true> OuterAllocTrueHasTrueTypes;
+ typedef test_allocator<tagged_integer<1>, 1, false> InnerAlloc1FalseHasTrueTypes;
+ typedef test_allocator<tagged_integer<1>, 1, true> InnerAlloc1TrueHasTrueTypes;
+ typedef test_allocator<tagged_integer<2>, 2, false> InnerAlloc2FalseHasTrueTypes;
+ typedef test_allocator<tagged_integer<2>, 2, true> InnerAlloc2TrueHasTrueTypes;
//
typedef scoped_allocator_adaptor< OuterAlloc > Scoped0Inner;
@@ -374,40 +380,40 @@ int main()
{
//Propagation test
- typedef scoped_allocator_adaptor< OuterAllocFalsePropagate > Scoped0InnerF;
- typedef scoped_allocator_adaptor< OuterAllocTruePropagate > Scoped0InnerT;
- typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
- , InnerAlloc1FalsePropagate > Scoped1InnerFF;
- typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
- , InnerAlloc1TruePropagate > Scoped1InnerFT;
- typedef scoped_allocator_adaptor< OuterAllocTruePropagate
- , InnerAlloc1FalsePropagate > Scoped1InnerTF;
- typedef scoped_allocator_adaptor< OuterAllocTruePropagate
- , InnerAlloc1TruePropagate > Scoped1InnerTT;
- typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
- , InnerAlloc1FalsePropagate
- , InnerAlloc2FalsePropagate > Scoped2InnerFFF;
- typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
- , InnerAlloc1FalsePropagate
- , InnerAlloc2TruePropagate > Scoped2InnerFFT;
- typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
- , InnerAlloc1TruePropagate
- , InnerAlloc2FalsePropagate > Scoped2InnerFTF;
- typedef scoped_allocator_adaptor< OuterAllocFalsePropagate
- , InnerAlloc1TruePropagate
- , InnerAlloc2TruePropagate > Scoped2InnerFTT;
- typedef scoped_allocator_adaptor< OuterAllocTruePropagate
- , InnerAlloc1FalsePropagate
- , InnerAlloc2FalsePropagate > Scoped2InnerTFF;
- typedef scoped_allocator_adaptor< OuterAllocTruePropagate
- , InnerAlloc1FalsePropagate
- , InnerAlloc2TruePropagate > Scoped2InnerTFT;
- typedef scoped_allocator_adaptor< OuterAllocTruePropagate
- , InnerAlloc1TruePropagate
- , InnerAlloc2FalsePropagate > Scoped2InnerTTF;
- typedef scoped_allocator_adaptor< OuterAllocTruePropagate
- , InnerAlloc1TruePropagate
- , InnerAlloc2TruePropagate > Scoped2InnerTTT;
+ typedef scoped_allocator_adaptor< OuterAllocFalseHasTrueTypes > Scoped0InnerF;
+ typedef scoped_allocator_adaptor< OuterAllocTrueHasTrueTypes > Scoped0InnerT;
+ typedef scoped_allocator_adaptor< OuterAllocFalseHasTrueTypes
+ , InnerAlloc1FalseHasTrueTypes > Scoped1InnerFF;
+ typedef scoped_allocator_adaptor< OuterAllocFalseHasTrueTypes
+ , InnerAlloc1TrueHasTrueTypes > Scoped1InnerFT;
+ typedef scoped_allocator_adaptor< OuterAllocTrueHasTrueTypes
+ , InnerAlloc1FalseHasTrueTypes > Scoped1InnerTF;
+ typedef scoped_allocator_adaptor< OuterAllocTrueHasTrueTypes
+ , InnerAlloc1TrueHasTrueTypes > Scoped1InnerTT;
+ typedef scoped_allocator_adaptor< OuterAllocFalseHasTrueTypes
+ , InnerAlloc1FalseHasTrueTypes
+ , InnerAlloc2FalseHasTrueTypes > Scoped2InnerFFF;
+ typedef scoped_allocator_adaptor< OuterAllocFalseHasTrueTypes
+ , InnerAlloc1FalseHasTrueTypes
+ , InnerAlloc2TrueHasTrueTypes > Scoped2InnerFFT;
+ typedef scoped_allocator_adaptor< OuterAllocFalseHasTrueTypes
+ , InnerAlloc1TrueHasTrueTypes
+ , InnerAlloc2FalseHasTrueTypes > Scoped2InnerFTF;
+ typedef scoped_allocator_adaptor< OuterAllocFalseHasTrueTypes
+ , InnerAlloc1TrueHasTrueTypes
+ , InnerAlloc2TrueHasTrueTypes > Scoped2InnerFTT;
+ typedef scoped_allocator_adaptor< OuterAllocTrueHasTrueTypes
+ , InnerAlloc1FalseHasTrueTypes
+ , InnerAlloc2FalseHasTrueTypes > Scoped2InnerTFF;
+ typedef scoped_allocator_adaptor< OuterAllocTrueHasTrueTypes
+ , InnerAlloc1FalseHasTrueTypes
+ , InnerAlloc2TrueHasTrueTypes > Scoped2InnerTFT;
+ typedef scoped_allocator_adaptor< OuterAllocTrueHasTrueTypes
+ , InnerAlloc1TrueHasTrueTypes
+ , InnerAlloc2FalseHasTrueTypes > Scoped2InnerTTF;
+ typedef scoped_allocator_adaptor< OuterAllocTrueHasTrueTypes
+ , InnerAlloc1TrueHasTrueTypes
+ , InnerAlloc2TrueHasTrueTypes > Scoped2InnerTTT;
//propagate_on_container_copy_assignment
//0 inner
@@ -465,6 +471,24 @@ int main()
BOOST_STATIC_ASSERT(( Scoped2InnerTFT::propagate_on_container_swap::value ));
BOOST_STATIC_ASSERT(( Scoped2InnerTTF::propagate_on_container_swap::value ));
BOOST_STATIC_ASSERT(( Scoped2InnerTTT::propagate_on_container_swap::value ));
+ //is_always_equal
+ //0 inner
+ BOOST_STATIC_ASSERT(( !Scoped0InnerF::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( Scoped0InnerT::is_always_equal::value ));
+ //1 inner
+ BOOST_STATIC_ASSERT(( !Scoped1InnerFF::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped1InnerFT::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped1InnerTF::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( Scoped1InnerTT::is_always_equal::value ));
+ //2 inner
+ BOOST_STATIC_ASSERT(( !Scoped2InnerFFF::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped2InnerFFT::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped2InnerFTF::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped2InnerFTT::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped2InnerTFF::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped2InnerTFT::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( !Scoped2InnerTTF::is_always_equal::value ));
+ BOOST_STATIC_ASSERT(( Scoped2InnerTTT::is_always_equal::value ));
}
//Default constructor
@@ -475,8 +499,8 @@ int main()
{
Scoped0Inner s0i2;
Scoped1Inner s1i2;
- boost::container::swap_dispatch(s0i, s0i2);
- boost::container::swap_dispatch(s1i, s1i2);
+ boost::adl_move_swap(s0i, s0i2);
+ boost::adl_move_swap(s1i, s1i2);
}
}
diff --git a/libs/container/test/scoped_allocator_usage_test.cpp b/libs/container/test/scoped_allocator_usage_test.cpp
index 111d12a71..61607e7e6 100644
--- a/libs/container/test/scoped_allocator_usage_test.cpp
+++ b/libs/container/test/scoped_allocator_usage_test.cpp
@@ -1,3 +1,12 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
#include <memory>
@@ -7,6 +16,7 @@
#include <boost/container/list.hpp>
#include <boost/container/slist.hpp>
#include <boost/container/stable_vector.hpp>
+#include <boost/container/small_vector.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/map.hpp>
@@ -48,6 +58,12 @@ public:
std::allocator<Ty> m_allocator;
template <typename T> friend class SimpleAllocator;
+
+ friend bool operator == (const SimpleAllocator &, const SimpleAllocator &)
+ { return true; }
+
+ friend bool operator != (const SimpleAllocator &, const SimpleAllocator &)
+ { return false; }
};
class alloc_int
@@ -125,6 +141,7 @@ typedef deque<alloc_int, AllocIntAllocator> Deque;
typedef list<alloc_int, AllocIntAllocator> List;
typedef slist<alloc_int, AllocIntAllocator> Slist;
typedef stable_vector<alloc_int, AllocIntAllocator> StableVector;
+typedef small_vector<alloc_int, 9, AllocIntAllocator> SmallVector;
/////////
//is_unique_assoc
@@ -136,26 +153,26 @@ struct is_unique_assoc
static const bool value = false;
};
-template<class K, class V, class C, class A>
-struct is_unique_assoc< map<K, V, C, A> >
+template<class Key, class T, class Compare, class Allocator>
+struct is_unique_assoc< map<Key, T, Compare, Allocator> >
{
static const bool value = true;
};
-template<class K, class V, class C, class A>
-struct is_unique_assoc< flat_map<K, V, C, A> >
+template<class Key, class T, class Compare, class Allocator>
+struct is_unique_assoc< flat_map<Key, T, Compare, Allocator> >
{
static const bool value = true;
};
-template<class V, class C, class A>
-struct is_unique_assoc< set<V, C, A> >
+template<class Key, class Compare, class Allocator>
+struct is_unique_assoc< set<Key, Compare, Allocator> >
{
static const bool value = true;
};
-template<class V, class C, class A>
-struct is_unique_assoc< flat_set<V, C, A> >
+template<class Key, class Compare, class Allocator>
+struct is_unique_assoc< flat_set<Key, Compare, Allocator> >
{
static const bool value = true;
};
@@ -171,26 +188,26 @@ struct is_map
static const bool value = false;
};
-template<class K, class V, class C, class A>
-struct is_map< map<K, V, C, A> >
+template<class Key, class T, class Compare, class Allocator>
+struct is_map< map<Key, T, Compare, Allocator> >
{
static const bool value = true;
};
-template<class K, class V, class C, class A>
-struct is_map< flat_map<K, V, C, A> >
+template<class Key, class T, class Compare, class Allocator>
+struct is_map< flat_map<Key, T, Compare, Allocator> >
{
static const bool value = true;
};
-template<class K, class V, class C, class A>
-struct is_map< multimap<K, V, C, A> >
+template<class Key, class T, class Compare, class Allocator>
+struct is_map< multimap<Key, T, Compare, Allocator> >
{
static const bool value = true;
};
-template<class K, class V, class C, class A>
-struct is_map< flat_multimap<K, V, C, A> >
+template<class Key, class T, class Compare, class Allocator>
+struct is_map< flat_multimap<Key, T, Compare, Allocator> >
{
static const bool value = true;
};
@@ -201,26 +218,26 @@ struct is_set
static const bool value = false;
};
-template<class V, class C, class A>
-struct is_set< set<V, C, A> >
+template<class Key, class Compare, class Allocator>
+struct is_set< set<Key, Compare, Allocator> >
{
static const bool value = true;
};
-template<class V, class C, class A>
-struct is_set< flat_set<V, C, A> >
+template<class Key, class Compare, class Allocator>
+struct is_set< flat_set<Key, Compare, Allocator> >
{
static const bool value = true;
};
-template<class V, class C, class A>
-struct is_set< multiset<V, C, A> >
+template<class Key, class Compare, class Allocator>
+struct is_set< multiset<Key, Compare, Allocator> >
{
static const bool value = true;
};
-template<class V, class C, class A>
-struct is_set< flat_multiset<V, C, A> >
+template<class Key, class Compare, class Allocator>
+struct is_set< flat_multiset<Key, Compare, Allocator> >
{
static const bool value = true;
};
@@ -229,106 +246,97 @@ struct is_set< flat_multiset<V, C, A> >
//container_wrapper
/////////
+//Try to define-allocator_aware requirements
template< class Container
, bool Assoc = is_set<Container>::value || is_map<Container>::value
, bool UniqueAssoc = is_unique_assoc<Container>::value
, bool Map = is_map<Container>::value
>
-struct container_wrapper
- : public Container
+struct container_wrapper_inserter
{
- typedef typename Container::allocator_type allocator_type;
+ typedef typename Container::const_iterator const_iterator;
+ typedef typename Container::iterator iterator;
- container_wrapper(const allocator_type &a)
- : Container(a)
- {}
+ template<class Arg>
+ static iterator emplace(Container &c, const_iterator p, const Arg &arg)
+ { return c.emplace(p, arg); }
};
template<class Container> //map
-struct container_wrapper<Container, true, true, true>
- : public Container
+struct container_wrapper_inserter<Container, true, true, true>
{
- typedef typename Container::allocator_type allocator_type;
- typedef typename Container::key_compare key_compare;
- typedef typename Container::value_type value_type;
typedef typename Container::const_iterator const_iterator;
typedef typename Container::iterator iterator;
- container_wrapper(const allocator_type &a)
- : Container(key_compare(), a)
- {}
-
template<class Arg>
- iterator emplace(const_iterator, const Arg &arg)
- {
- return this->Container::emplace(arg, arg).first;
- }
+ static iterator emplace(Container &c, const_iterator, const Arg &arg)
+ { return c.emplace(arg, arg).first; }
};
template<class Container> //set
-struct container_wrapper<Container, true, true, false>
- : public Container
+struct container_wrapper_inserter<Container, true, true, false>
{
- typedef typename Container::allocator_type allocator_type;
- typedef typename Container::key_compare key_compare;
- typedef typename Container::value_type value_type;
typedef typename Container::const_iterator const_iterator;
typedef typename Container::iterator iterator;
- container_wrapper(const allocator_type &a)
- : Container(key_compare(), a)
- {}
-
template<class Arg>
- iterator emplace(const_iterator, const Arg &arg)
- {
- return this->Container::emplace(arg).first;
- }
+ static iterator emplace(Container &c, const_iterator, const Arg &arg)
+ { return c.emplace(arg).first; }
};
template<class Container> //multimap
-struct container_wrapper<Container, true, false, true>
- : public Container
+struct container_wrapper_inserter<Container, true, false, true>
{
- typedef typename Container::value_type value_type;
- typedef typename Container::key_compare key_compare;
- typedef typename Container::allocator_type allocator_type;
typedef typename Container::const_iterator const_iterator;
typedef typename Container::iterator iterator;
- container_wrapper(const allocator_type &a)
- : Container(key_compare(), a)
- {}
-
template<class Arg>
- iterator emplace(const_iterator, const Arg &arg)
- {
- return this->Container::emplace(arg, arg);
- }
+ static iterator emplace(Container &c, const_iterator, const Arg &arg)
+ { return c.emplace(arg, arg); }
};
//multiset
template<class Container> //multimap
-struct container_wrapper<Container, true, false, false>
+struct container_wrapper_inserter<Container, true, false, false>
+{
+ typedef typename Container::const_iterator const_iterator;
+ typedef typename Container::iterator iterator;
+
+ template<class Arg>
+ static iterator emplace(Container &c, const_iterator, const Arg &arg)
+ { return c.emplace(arg); }
+};
+
+template< class Container>
+struct container_wrapper
: public Container
{
- typedef typename Container::value_type value_type;
- typedef typename Container::key_compare key_compare;
+ private:
+ BOOST_COPYABLE_AND_MOVABLE(container_wrapper)
+
+ public:
typedef typename Container::allocator_type allocator_type;
typedef typename Container::const_iterator const_iterator;
typedef typename Container::iterator iterator;
container_wrapper(const allocator_type &a)
- : Container(key_compare(), a)
+ : Container(a)
+ {}
+
+ container_wrapper(BOOST_RV_REF(container_wrapper) o, const allocator_type &a)
+ : Container(BOOST_MOVE_BASE(Container, o), a)
+ {}
+
+ container_wrapper(const container_wrapper &o, const allocator_type &a)
+ : Container(o, a)
{}
template<class Arg>
- iterator emplace(const_iterator, const Arg &arg)
- {
- return this->Container::emplace(arg);
- }
+ iterator emplace(const_iterator p, const Arg &arg)
+ { return container_wrapper_inserter<Container>::emplace(*this, p, arg); }
};
+
bool test_value_and_state_equals(const alloc_int &r, int value, int state)
{ return r.get_value() == value && r.get_allocator_state() == state; }
@@ -345,19 +353,42 @@ bool one_level_allocator_propagation_test()
{
typedef container_wrapper<Container> ContainerWrapper;
typedef typename ContainerWrapper::iterator iterator;
- ContainerWrapper c(SimpleAllocator<MapNode>(5));
+ typedef typename ContainerWrapper::allocator_type allocator_type;
+ typedef typename ContainerWrapper::value_type value_type;
+ {
+ ContainerWrapper c(allocator_type(SimpleAllocator<value_type>(5)));
- c.clear();
- iterator it = c.emplace(c.cbegin(), 42);
+ c.clear();
+ iterator it = c.emplace(c.cbegin(), 42);
- if(!test_value_and_state_equals(*it, 42, 5))
- return false;
+ if(!test_value_and_state_equals(*it, 42, 5))
+ return false;
+ }
+ {
+ ContainerWrapper c2(allocator_type(SimpleAllocator<value_type>(4)));
+ ContainerWrapper c(::boost::move(c2), allocator_type(SimpleAllocator<value_type>(5)));
+ c.clear();
+ iterator it = c.emplace(c.cbegin(), 42);
+
+ if(!test_value_and_state_equals(*it, 42, 5))
+ return false;
+ }/*
+ {
+ ContainerWrapper c2(allocator_type(SimpleAllocator<value_type>(3)));
+ ContainerWrapper c(c2, allocator_type(SimpleAllocator<value_type>(5)));
+
+ c.clear();
+ iterator it = c.emplace(c.cbegin(), 42);
+
+ if(!test_value_and_state_equals(*it, 42, 5))
+ return false;
+ }*/
return true;
}
int main()
-{
+{/*
//unique assoc
if(!one_level_allocator_propagation_test<FlatMap>())
return 1;
@@ -375,7 +406,7 @@ int main()
if(!one_level_allocator_propagation_test<FlatMultiSet>())
return 1;
if(!one_level_allocator_propagation_test<MultiSet>())
- return 1;
+ return 1;*/
//sequence containers
if(!one_level_allocator_propagation_test<Vector>())
return 1;
@@ -387,6 +418,8 @@ int main()
return 1;
if(!one_level_allocator_propagation_test<StableVector>())
return 1;
+ if(!one_level_allocator_propagation_test<SmallVector>())
+ return 1;
return 0;
}
diff --git a/libs/container/test/set_test.cpp b/libs/container/test/set_test.cpp
index 4c0be9c4f..b305868de 100644
--- a/libs/container/test/set_test.cpp
+++ b/libs/container/test/set_test.cpp
@@ -176,7 +176,7 @@ public:
set<recursive_set>::const_iterator cit_;
set<recursive_set>::reverse_iterator rit_;
set<recursive_set>::const_reverse_iterator crit_;
-
+
friend bool operator< (const recursive_set &a, const recursive_set &b)
{ return a.id_ < b.id_; }
};
@@ -194,7 +194,7 @@ class recursive_multiset
multiset<recursive_multiset>::const_iterator cit_;
multiset<recursive_multiset>::reverse_iterator rit_;
multiset<recursive_multiset>::const_reverse_iterator crit_;
-
+
friend bool operator< (const recursive_multiset &a, const recursive_multiset &b)
{ return a.id_ < b.id_; }
};
@@ -212,37 +212,35 @@ void test_move()
move_assign.swap(original);
}
-template<class T, class A>
-class set_propagate_test_wrapper
- : public boost::container::set<T, std::less<T>, A
- //tree_assoc_defaults
- >
-{
- BOOST_COPYABLE_AND_MOVABLE(set_propagate_test_wrapper)
- typedef boost::container::set<T, std::less<T>, A > Base;
- public:
- set_propagate_test_wrapper()
- : Base()
- {}
+struct boost_container_set;
+struct boost_container_multiset;
- set_propagate_test_wrapper(const set_propagate_test_wrapper &x)
- : Base(x)
- {}
-
- set_propagate_test_wrapper(BOOST_RV_REF(set_propagate_test_wrapper) x)
- : Base(boost::move(static_cast<Base&>(x)))
- {}
-
- set_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(set_propagate_test_wrapper) x)
- { this->Base::operator=(x); return *this; }
+namespace boost {
+namespace container {
+namespace test {
- set_propagate_test_wrapper &operator=(BOOST_RV_REF(set_propagate_test_wrapper) x)
- { this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
+template<>
+struct alloc_propagate_base<boost_container_set>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::set<T, std::less<T>, Allocator> type;
+ };
+};
- void swap(set_propagate_test_wrapper &x)
- { this->Base::swap(x); }
+template<>
+struct alloc_propagate_base<boost_container_multiset>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::multiset<T, std::less<T>, Allocator> type;
+ };
};
+}}} //boost::container::test
+
template<class VoidAllocator, boost::container::tree_type_enum tree_type_value>
struct GetAllocatorSet
{
@@ -324,36 +322,7 @@ int test_set_variants()
return 0;
}
-template<typename SetType>
-bool test_support_for_initialization_list_for()
-{
-#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
- std::initializer_list<int> il = {1, 2, 3, 4, 5};
- SetType expected(il.begin(), il.end());
- {
- SetType sil = il;
- if (sil != expected)
- return false;
-
- SetType sil_ordered(ordered_unique_range, il);
- if(sil_ordered != expected)
- return false;
-
- SetType sil_assign = {99, 100, 101, 102, 103, 104, 105};
- sil_assign = il;
- if(sil_assign != expected)
- return false;
- }
- {
- SetType sil;
- sil.insert(il);
- if(sil != expected)
- return false;
- }
- return true;
-#endif
- return true;
-}
+
int main ()
{
//Recursive container instantiation
@@ -363,8 +332,8 @@ int main ()
}
//Allocator argument container
{
- set<int> set_((std::allocator<int>()));
- multiset<int> multiset_((std::allocator<int>()));
+ set<int> set_((set<int>::allocator_type()));
+ multiset<int> multiset_((multiset<int>::allocator_type()));
}
//Now test move semantics
{
@@ -427,13 +396,16 @@ int main ()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<set_propagate_test_wrapper>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_set>())
+ return 1;
+
+ if(!boost::container::test::test_propagate_allocator<boost_container_multiset>())
return 1;
- if(!test_support_for_initialization_list_for<set<int> >())
+ if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<set<int> >())
return 1;
- if(!test_support_for_initialization_list_for<multiset<int> >())
+ if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<multiset<int> >())
return 1;
////////////////////////////////////
diff --git a/libs/container/test/set_test.hpp b/libs/container/test/set_test.hpp
index 90db09323..1ab8af54c 100644
--- a/libs/container/test/set_test.hpp
+++ b/libs/container/test/set_test.hpp
@@ -13,22 +13,17 @@
#include <boost/container/detail/config_begin.hpp>
#include "check_equal_containers.hpp"
-#include <memory>
-#include <set>
-#include <functional>
#include "print_container.hpp"
#include <boost/move/utility_core.hpp>
#include <boost/move/iterator.hpp>
#include <boost/move/make_unique.hpp>
-#include <string>
-#include <boost/intrusive/detail/has_member_function_callable_with.hpp>
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME rebalance
-#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace test {
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace test {
#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
-#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, <boost/intrusive/detail/has_member_function_callable_with.hpp>))
-#include BOOST_PP_ITERATE()
-
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 0
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0
+#include <boost/intrusive/detail/has_member_function_callable_with.hpp>
namespace boost{
namespace container {
@@ -108,6 +103,20 @@ int set_test_copyable(boost::container::container_detail::true_type)
if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy))
return 1;
}
+ {
+ //Now, test copy constructor
+ MyBoostSet boostsetcopy(boostset, typename MyBoostSet::allocator_type());
+ MyStdSet stdsetcopy(stdset);
+
+ if(!CheckEqualContainers(boostsetcopy, stdsetcopy))
+ return 1;
+
+ MyBoostMultiSet boostmsetcopy(boostmultiset, typename MyBoostSet::allocator_type());
+ MyStdMultiSet stdmsetcopy(stdmultiset);
+
+ if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy))
+ return 1;
+ }
return 0;
}
@@ -132,6 +141,54 @@ int set_test ()
MyStdMultiSet &stdmultiset = *pstdmultiset;
//Test construction from a range
+ { //Set(beg, end, compare)
+ IntType aux_vect[50];
+ for(int i = 0; i < 50; ++i){
+ IntType move_me(i/2);
+ aux_vect[i] = boost::move(move_me);
+ }
+ int aux_vect2[50];
+ for(int i = 0; i < 50; ++i){
+ aux_vect2[i] = i/2;
+ }
+ IntType aux_vect3[50];
+ for(int i = 0; i < 50; ++i){
+ IntType move_me(i/2);
+ aux_vect3[i] = boost::move(move_me);
+ }
+ ::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>
+ (boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::key_compare());
+ ::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
+ if(!test::CheckEqualContainers(*pboostset, *pstdset)) return 1;
+ ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>
+ (boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::key_compare());
+ ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
+ if(!test::CheckEqualContainers(*pboostmultiset, *pstdmultiset)) return 1;
+ }
+ { //Set(beg, end, alloc)
+ IntType aux_vect[50];
+ for(int i = 0; i < 50; ++i){
+ IntType move_me(i/2);
+ aux_vect[i] = boost::move(move_me);
+ }
+ int aux_vect2[50];
+ for(int i = 0; i < 50; ++i){
+ aux_vect2[i] = i/2;
+ }
+ IntType aux_vect3[50];
+ for(int i = 0; i < 50; ++i){
+ IntType move_me(i/2);
+ aux_vect3[i] = boost::move(move_me);
+ }
+ ::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>
+ (boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::allocator_type());
+ ::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
+ if(!test::CheckEqualContainers(*pboostset, *pstdset)) return 1;
+ ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>
+ (boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::allocator_type());
+ ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
+ if(!test::CheckEqualContainers(*pboostmultiset, *pstdmultiset)) return 1;
+ }
{
IntType aux_vect[50];
for(int i = 0; i < 50; ++i){
@@ -188,7 +245,19 @@ int set_test ()
aux_vect3[i] = boost::move(move_me);
}
-
+ //some comparison operators
+ if(!(boostset2 == boostset2))
+ return 1;
+ if(boostset2 != boostset2)
+ return 1;
+ if(boostset2 < boostset2)
+ return 1;
+ if(boostset2 > boostset2)
+ return 1;
+ if(!(boostset2 <= boostset2))
+ return 1;
+ if(!(boostset2 >= boostset2))
+ return 1;
::boost::movelib::unique_ptr<MyBoostSet> const pboostset3 = ::boost::movelib::make_unique<MyBoostSet>
( ordered_unique_range
@@ -636,6 +705,47 @@ int set_test ()
return 0;
}
+template<typename SetType>
+bool test_set_methods_with_initializer_list_as_argument_for()
+{
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ std::initializer_list<int> il = { 1, 2, 3, 4, 5, 5 };
+ std::initializer_list<int> ilu = { 1, 2, 3, 4, 5 };
+ SetType expected(il.begin(), il.end());
+ SetType expectedu(ilu.begin(), ilu.end());
+ {
+ SetType sil((il));
+ if (sil != expected)
+ return false;
+
+ SetType sila(il, typename SetType::allocator_type());
+ if (sila != expected)
+ return false;
+
+ SetType silca(il, typename SetType::key_compare(), typename SetType::allocator_type());
+ if (silca != expected)
+ return false;
+
+ SetType sil_ordered(ordered_unique_range, ilu);
+ if (sil_ordered != expectedu)
+ return false;
+
+ SetType sil_assign = { 99, 100, 101, 102, 103, 104, 105 };
+ sil_assign = il;
+ if (sil_assign != expected)
+ return false;
+ }
+ {
+ SetType sil;
+ sil.insert(il);
+ if (sil != expected)
+ return false;
+ }
+ return true;
+#endif
+ return true;
+}
+
} //namespace test{
} //namespace container {
} //namespace boost{
diff --git a/libs/container/test/slist_test.cpp b/libs/container/test/slist_test.cpp
index 6e7cda6e0..f73056ba2 100644
--- a/libs/container/test/slist_test.cpp
+++ b/libs/container/test/slist_test.cpp
@@ -59,7 +59,7 @@ public:
slist<recursive_slist> slist_;
slist<recursive_slist>::iterator it_;
slist<recursive_slist>::const_iterator cit_;
-
+
recursive_slist &operator=(const recursive_slist &o)
{ slist_ = o.slist_; return *this; }
};
@@ -121,7 +121,12 @@ bool test_support_for_initializer_list()
if(sl != expected_list)
return false;
}
-
+ {
+ slist<int> sl({ 1, 2 }, slist<int>::allocator_type());
+ sl = il;
+ if (sl != expected_list)
+ return false;
+ }
{
slist<int> sl = {4, 5};
sl.assign(il);
@@ -147,6 +152,24 @@ bool test_support_for_initializer_list()
return true;
}
+struct boost_container_slist;
+
+namespace boost {
+namespace container {
+namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_slist>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::slist<T, Allocator> type;
+ };
+};
+
+}}}
+
int main ()
{
recursive_slist_test();
@@ -202,7 +225,7 @@ int main ()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<slist>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_slist>())
return 1;
if(!test_support_for_initializer_list())
diff --git a/libs/container/test/small_vector_test.cpp b/libs/container/test/small_vector_test.cpp
new file mode 100644
index 000000000..10a939eec
--- /dev/null
+++ b/libs/container/test/small_vector_test.cpp
@@ -0,0 +1,183 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include <boost/container/small_vector.hpp>
+#include "vector_test.hpp"
+#include "movable_int.hpp"
+#include "propagate_allocator_test.hpp"
+#include "default_init_test.hpp"
+
+#include <boost/container/allocator.hpp>
+#include <boost/container/node_allocator.hpp>
+#include <boost/container/adaptive_pool.hpp>
+
+#include <iostream>
+
+namespace boost {
+namespace container {
+
+template class small_vector<char, 0>;
+template class small_vector<char, 1>;
+template class small_vector<char, 2>;
+template class small_vector<char, 10>;
+
+template class small_vector<int, 0>;
+template class small_vector<int, 1>;
+template class small_vector<int, 2>;
+template class small_vector<int, 10>;
+
+//Explicit instantiation to detect compilation errors
+template class boost::container::small_vector
+ < test::movable_and_copyable_int
+ , 10
+ , test::simple_allocator<test::movable_and_copyable_int> >;
+
+template class boost::container::small_vector
+ < test::movable_and_copyable_int
+ , 10
+ , test::dummy_test_allocator<test::movable_and_copyable_int> >;
+
+template class boost::container::small_vector
+ < test::movable_and_copyable_int
+ , 10
+ , std::allocator<test::movable_and_copyable_int> >;
+
+template class boost::container::small_vector
+ < test::movable_and_copyable_int
+ , 10
+ , allocator<test::movable_and_copyable_int> >;
+
+template class boost::container::small_vector
+ < test::movable_and_copyable_int
+ , 10
+ , adaptive_pool<test::movable_and_copyable_int> >;
+
+template class boost::container::small_vector
+ < test::movable_and_copyable_int
+ , 10
+ , node_allocator<test::movable_and_copyable_int> >;
+
+}}
+
+struct boost_container_small_vector;
+
+namespace boost { namespace container { namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_small_vector>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::small_vector<T, 10, Allocator> type;
+ };
+};
+
+}}} //namespace boost::container::test
+
+bool test_small_vector_base_test()
+{
+ typedef boost::container::small_vector_base<int> smb_t;
+ {
+ typedef boost::container::small_vector<int, 5> sm5_t;
+ sm5_t sm5;
+ smb_t &smb = sm5;
+ smb.push_back(1);
+ sm5_t sm5_copy(sm5);
+ sm5_copy.push_back(1);
+ if (!boost::container::test::CheckEqualContainers(sm5, smb))
+ return false;
+ }
+ {
+ typedef boost::container::small_vector<int, 5> sm7_t;
+ sm7_t sm7;
+ smb_t &smb = sm7;
+ smb.push_back(2);
+ sm7_t sm7_copy(sm7);
+ sm7_copy.push_back(2);
+ if (!boost::container::test::CheckEqualContainers(sm7, smb))
+ return false;
+ }
+ return true;
+}
+
+int main()
+{
+ using namespace boost::container;
+/*
+ typedef small_vector<char, 0>::storage_test storage_test;
+ std::cout << "needed_extra_storages: " << storage_test::needed_extra_storages << '\n';
+ std::cout << "needed_bytes: " << storage_test::needed_bytes << '\n';
+ std::cout << "header_bytes: " << storage_test::header_bytes << '\n';
+ std::cout << "s_start: " << storage_test::s_start << '\n';
+
+ //char
+ std::cout << "sizeof(small_vector<char, 0>): " << sizeof(small_vector<char, 0>) << " extra: " << small_vector<char, 0>::needed_extra_storages << " internal storage: " << small_vector<char, 0>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<char, 1>): " << sizeof(small_vector<char, 1>) << " extra: " << small_vector<char, 1>::needed_extra_storages << " internal storage: " << small_vector<char, 1>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<char, 2>): " << sizeof(small_vector<char, 2>) << " extra: " << small_vector<char, 2>::needed_extra_storages << " internal storage: " << small_vector<char, 2>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<char, 3>): " << sizeof(small_vector<char, 3>) << " extra: " << small_vector<char, 3>::needed_extra_storages << " internal storage: " << small_vector<char, 3>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<char, 4>): " << sizeof(small_vector<char, 4>) << " extra: " << small_vector<char, 4>::needed_extra_storages << " internal storage: " << small_vector<char, 4>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<char, 5>): " << sizeof(small_vector<char, 5>) << " extra: " << small_vector<char, 5>::needed_extra_storages << " internal storage: " << small_vector<char, 5>::internal_capacity() << '\n';
+ std::cout << "\n";
+
+ //short
+ std::cout << "sizeof(small_vector<short, 0>): " << sizeof(small_vector<short, 0>) << " extra: " << small_vector<short, 0>::needed_extra_storages << " internal storage: " << small_vector<short, 0>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<short, 1>): " << sizeof(small_vector<short, 1>) << " extra: " << small_vector<short, 1>::needed_extra_storages << " internal storage: " << small_vector<short, 1>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<short, 2>): " << sizeof(small_vector<short, 2>) << " extra: " << small_vector<short, 2>::needed_extra_storages << " internal storage: " << small_vector<short, 2>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<short, 3>): " << sizeof(small_vector<short, 3>) << " extra: " << small_vector<short, 3>::needed_extra_storages << " internal storage: " << small_vector<short, 3>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<short, 4>): " << sizeof(small_vector<short, 4>) << " extra: " << small_vector<short, 4>::needed_extra_storages << " internal storage: " << small_vector<short, 4>::internal_capacity() << '\n';
+ std::cout << "sizeof(small_vector<short, 5>): " << sizeof(small_vector<short, 5>) << " extra: " << small_vector<short, 5>::needed_extra_storages << " internal storage: " << small_vector<short, 5>::internal_capacity() << '\n';
+*/
+ if(test::vector_test< small_vector<int, 0> >())
+ return 1;
+
+ if(test::vector_test< small_vector<int, 2000> >())
+ return 1;
+
+
+ ////////////////////////////////////
+ // Default init test
+ ////////////////////////////////////
+ if(!test::default_init_test< vector<int, test::default_init_allocator<int> > >()){
+ std::cerr << "Default init test failed" << std::endl;
+ return 1;
+ }
+
+ ////////////////////////////////////
+ // Emplace testing
+ ////////////////////////////////////
+ const test::EmplaceOptions Options = (test::EmplaceOptions)(test::EMPLACE_BACK | test::EMPLACE_BEFORE);
+ if(!boost::container::test::test_emplace< vector<test::EmplaceInt>, Options>()){
+ return 1;
+ }
+
+ ////////////////////////////////////
+ // Allocator propagation testing
+ ////////////////////////////////////
+ if(!boost::container::test::test_propagate_allocator<boost_container_small_vector>()){
+ return 1;
+ }
+
+ ////////////////////////////////////
+ // Initializer lists testing
+ ////////////////////////////////////
+ if(!boost::container::test::test_vector_methods_with_initializer_list_as_argument_for
+ < boost::container::small_vector<int, 5> >()) {
+ return 1;
+ }
+
+ ////////////////////////////////////
+ // Small vector base
+ ////////////////////////////////////
+ if (!test_small_vector_base_test()){
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/libs/container/test/stable_vector_test.cpp b/libs/container/test/stable_vector_test.cpp
index eeb3c7faf..3ff73e3e4 100644
--- a/libs/container/test/stable_vector_test.cpp
+++ b/libs/container/test/stable_vector_test.cpp
@@ -9,11 +9,7 @@
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp>
-#include <algorithm>
#include <memory>
-#include <vector>
-#include <iostream>
-#include <functional>
#include <boost/container/stable_vector.hpp>
#include <boost/container/allocator.hpp>
@@ -70,7 +66,7 @@ class recursive_vector
stable_vector<recursive_vector>::const_iterator cit_;
stable_vector<recursive_vector>::reverse_iterator rit_;
stable_vector<recursive_vector>::const_reverse_iterator crit_;
-
+
recursive_vector &operator=(const recursive_vector &o)
{ vector_ = o.vector_; return *this; }
};
@@ -117,6 +113,23 @@ int test_cont_variants()
return 0;
}
+struct boost_container_stable_vector;
+
+namespace boost { namespace container { namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_stable_vector>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::stable_vector<T, Allocator> type;
+ };
+};
+
+}}} //namespace boost::container::test
+
+
int main()
{
recursive_vector_test();
@@ -180,15 +193,14 @@ int main()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<stable_vector>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_stable_vector>())
return 1;
////////////////////////////////////
// Initializer lists testing
////////////////////////////////////
- if(!boost::container::test::test_vector_methods_with_initializer_list_as_argument_for<
- boost::container::stable_vector<int>
- >())
+ if(!boost::container::test::test_vector_methods_with_initializer_list_as_argument_for
+ < boost::container::stable_vector<int> >())
{
std::cerr << "test_methods_with_initializer_list_as_argument failed" << std::endl;
return 1;
diff --git a/libs/container/test/static_vector_test.cpp b/libs/container/test/static_vector_test.cpp
index 69b5dd1bd..eb48f62e9 100644
--- a/libs/container/test/static_vector_test.cpp
+++ b/libs/container/test/static_vector_test.cpp
@@ -10,13 +10,13 @@
#include <boost/container/detail/config_begin.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/no_exceptions_support.hpp>
+#include <boost/container/vector.hpp>
+#include <boost/container/stable_vector.hpp>
+#include <boost/container/detail/iterator.hpp>
#include <vector>
#include <list>
-#include <boost/container/vector.hpp>
-#include <boost/container/stable_vector.hpp>
-
#include "static_vector_test.hpp"
namespace boost {
@@ -208,7 +208,7 @@ void test_pop_back_nd()
template <typename It1, typename It2>
void test_compare_ranges(It1 first1, It1 last1, It2 first2, It2 last2)
{
- BOOST_TEST(std::distance(first1, last1) == std::distance(first2, last2));
+ BOOST_TEST(boost::container::iterator_distance(first1, last1) == boost::container::iterator_distance(first2, last2));
for ( ; first1 != last1 && first2 != last2 ; ++first1, ++first2 )
BOOST_TEST(*first1 == *first2);
}
@@ -352,7 +352,7 @@ void test_insert(SV const& s, C const& c)
static_vector<T, N> s1(s);
typename C::const_iterator it = c.begin();
- std::advance(it, n);
+ boost::container::iterator_advance(it, n);
typename static_vector<T, N>::iterator
it1 = s1.insert(s1.begin() + i, c.begin(), it);
diff --git a/libs/container/test/static_vector_test.hpp b/libs/container/test/static_vector_test.hpp
index 1686955c7..ab931b274 100644
--- a/libs/container/test/static_vector_test.hpp
+++ b/libs/container/test/static_vector_test.hpp
@@ -78,6 +78,9 @@ private:
namespace boost {
+template <class T>
+struct has_nothrow_move;
+
template <>
struct has_nothrow_move<counting_value>
{
diff --git a/libs/container/test/string_test.cpp b/libs/container/test/string_test.cpp
index caa7eac76..2e3f6703d 100644
--- a/libs/container/test/string_test.cpp
+++ b/libs/container/test/string_test.cpp
@@ -13,7 +13,7 @@
#include <boost/container/string.hpp>
#include <string>
#include <vector>
-#include <algorithm>
+#include <boost/container/detail/algorithm.hpp> //equal()
#include <cstring>
#include <cstdio>
#include <cstddef>
@@ -68,7 +68,7 @@ template<class StrVector1, class StrVector2>
bool CheckEqualStringVector(StrVector1 *strvect1, StrVector2 *strvect2)
{
StringEqual comp;
- return std::equal(strvect1->begin(), strvect1->end(),
+ return boost::container::algo_equal(strvect1->begin(), strvect1->end(),
strvect2->begin(), comp);
}
@@ -432,35 +432,22 @@ bool test_expand_bwd()
return test::test_all_expand_bwd<string_type>();
}
-template<class T, class A>
-class string_propagate_test_wrapper
- : public basic_string<T, std::char_traits<T>, A>
-{
- BOOST_COPYABLE_AND_MOVABLE(string_propagate_test_wrapper)
- typedef basic_string<T, std::char_traits<T>, A> Base;
- public:
- string_propagate_test_wrapper()
- : Base()
- {}
-
- string_propagate_test_wrapper(const string_propagate_test_wrapper &x)
- : Base(x)
- {}
-
- string_propagate_test_wrapper(BOOST_RV_REF(string_propagate_test_wrapper) x)
- : Base(boost::move(static_cast<Base&>(x)))
- {}
-
- string_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(string_propagate_test_wrapper) x)
- { this->Base::operator=(x); return *this; }
+struct boost_container_string;
- string_propagate_test_wrapper &operator=(BOOST_RV_REF(string_propagate_test_wrapper) x)
- { this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
+namespace boost { namespace container { namespace test {
- void swap(string_propagate_test_wrapper &x)
- { this->Base::swap(x); }
+template<>
+struct alloc_propagate_base<boost_container_string>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::basic_string<T, std::char_traits<T>, Allocator> type;
+ };
};
+}}} //namespace boost::container::test
+
int main()
{
if(string_test<char>()){
@@ -480,7 +467,7 @@ int main()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<string_propagate_test_wrapper>())
+ if(!boost::container::test::test_propagate_allocator<boost_container_string>())
return 1;
////////////////////////////////////
diff --git a/libs/container/test/vector_test.cpp b/libs/container/test/vector_test.cpp
index 0ec3eb157..b84026237 100644
--- a/libs/container/test/vector_test.cpp
+++ b/libs/container/test/vector_test.cpp
@@ -7,10 +7,8 @@
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
-
#include <memory>
#include <iostream>
-#include <functional>
#include <boost/container/vector.hpp>
#include <boost/container/allocator.hpp>
@@ -147,6 +145,22 @@ int test_cont_variants()
return 0;
}
+struct boost_container_vector;
+
+namespace boost { namespace container { namespace test {
+
+template<>
+struct alloc_propagate_base<boost_container_vector>
+{
+ template <class T, class Allocator>
+ struct apply
+ {
+ typedef boost::container::vector<T, Allocator> type;
+ };
+};
+
+}}} //namespace boost::container::test
+
int main()
{
{
@@ -237,7 +251,7 @@ int main()
////////////////////////////////////
// Allocator propagation testing
////////////////////////////////////
- if(!boost::container::test::test_propagate_allocator<vector>()){
+ if(!boost::container::test::test_propagate_allocator<boost_container_vector>()){
return 1;
}
diff --git a/libs/container/test/vector_test.hpp b/libs/container/test/vector_test.hpp
index 7112849c2..6662d844f 100644
--- a/libs/container/test/vector_test.hpp
+++ b/libs/container/test/vector_test.hpp
@@ -12,28 +12,31 @@
#define BOOST_CONTAINER_TEST_VECTOR_TEST_HEADER
#include <boost/container/detail/config_begin.hpp>
-#include <algorithm>
-#include <memory>
+
#include <vector>
#include <iostream>
-#include <functional>
#include <list>
#include <boost/move/utility_core.hpp>
#include <boost/container/detail/mpl.hpp>
-#include "print_container.hpp"
-#include "check_equal_containers.hpp"
-#include "movable_int.hpp"
-#include <string>
-#include <vector>
-#include "emplace_test.hpp"
-#include "input_from_forward_iterator.hpp"
#include <boost/move/utility_core.hpp>
#include <boost/move/iterator.hpp>
#include <boost/move/make_unique.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <boost/static_assert.hpp>
+
+#include "print_container.hpp"
+#include "check_equal_containers.hpp"
+#include "movable_int.hpp"
+#include "emplace_test.hpp"
+#include "input_from_forward_iterator.hpp"
#include "insert_test.hpp"
+#include "container_common_tests.hpp"
+
+#include <cstddef>
+#include <string>
+#include <vector>
+
namespace boost{
namespace container {
@@ -83,7 +86,7 @@ bool vector_copyable_only(V1 &boostvector, V2 &stdvector, boost::container::cont
stdvector.push_back(int(3));
if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
}
- {
+ { //Vector(const Vector &)
::boost::movelib::unique_ptr<V1> const pv1 = ::boost::movelib::make_unique<V1>(boostvector);
::boost::movelib::unique_ptr<V2> const pv2 = ::boost::movelib::make_unique<V2>(stdvector);
@@ -96,6 +99,19 @@ bool vector_copyable_only(V1 &boostvector, V2 &stdvector, boost::container::cont
stdvector.assign(v2.begin(), v2.end());
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
}
+ { //Vector(const Vector &, alloc)
+ ::boost::movelib::unique_ptr<V1> const pv1 = ::boost::movelib::make_unique<V1>(boostvector, typename V1::allocator_type());
+ ::boost::movelib::unique_ptr<V2> const pv2 = ::boost::movelib::make_unique<V2>(stdvector);
+
+ V1 &v1 = *pv1;
+ V2 &v2 = *pv2;
+
+ boostvector.clear();
+ stdvector.clear();
+ boostvector.assign(v1.begin(), v1.end());
+ stdvector.assign(v2.begin(), v2.end());
+ if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
+ }
return true;
}
@@ -110,7 +126,36 @@ int vector_test()
if(!test_range_insertion<MyBoostVector>()){
return 1;
}
-
+ { //Vector(n)
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>(100);
+ ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>(100);
+ if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1;
+ }
+ { //Vector(n, alloc)
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>(100, typename MyBoostVector::allocator_type());
+ ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>(100);
+ if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1;
+ }
+ { //Vector(Vector &&)
+ ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>(100);
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>(100);
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 = ::boost::movelib::make_unique<MyBoostVector>(::boost::move(*boostvectorp));
+ if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
+ }
+ { //Vector(Vector &&, alloc)
+ ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>(100);
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>(100);
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 = ::boost::movelib::make_unique<MyBoostVector>
+ (::boost::move(*boostvectorp), typename MyBoostVector::allocator_type());
+ if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
+ }
+ { //Vector operator=(Vector &&)
+ ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>(100);
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>(100);
+ ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 = ::boost::movelib::make_unique<MyBoostVector>();
+ *boostvectorp2 = ::boost::move(*boostvectorp);
+ if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
+ }
{
::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>();
::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>();
@@ -167,7 +212,7 @@ int vector_test()
boostvector.insert(boostvector.end()
,boost::make_move_iterator(&aux_vect[0])
,boost::make_move_iterator(aux_vect + 50));
- if(std::size_t(std::distance(insert_it, boostvector.end())) != 50) return 1;
+ if(std::size_t(boost::container::iterator_distance(insert_it, boostvector.end())) != 50) return 1;
stdvector.insert(stdvector.end(), aux_vect2, aux_vect2 + 50);
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
@@ -276,6 +321,20 @@ int vector_test()
}
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
+ //some comparison operators
+ if(!(boostvector == boostvector))
+ return 1;
+ if(boostvector != boostvector)
+ return 1;
+ if(boostvector < boostvector)
+ return 1;
+ if(boostvector > boostvector)
+ return 1;
+ if(!(boostvector <= boostvector))
+ return 1;
+ if(!(boostvector >= boostvector))
+ return 1;
+
//Test insertion from list
{
std::list<int> l(50, int(1));
@@ -294,6 +353,10 @@ int vector_test()
stdvector.assign(l.begin(), l.end());
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
}
+
+ boostvector.resize(100);
+ if(!test_nth_index_of(boostvector))
+ return 1;
/* deque has no reserve or capacity
std::size_t cap = boostvector.capacity();
boostvector.reserve(cap*2);
@@ -326,12 +389,17 @@ template<typename VectorContainerType>
bool test_vector_methods_with_initializer_list_as_argument_for()
{
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ typedef typename VectorContainerType::allocator_type allocator_type;
{
const VectorContainerType testedVector = {1, 2, 3};
const std::vector<int> expectedVector = {1, 2, 3};
if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
}
-
+ {
+ const VectorContainerType testedVector( { 1, 2, 3 }, allocator_type() );
+ const std::vector<int> expectedVector = {1, 2, 3};
+ if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
+ }
{
VectorContainerType testedVector = {1, 2, 3};
testedVector = {11, 12, 13};