]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | /* Copyright 2016 Joaquin M Lopez Munoz. |
2 | * Distributed under the Boost Software License, Version 1.0. | |
3 | * (See accompanying file LICENSE_1_0.txt or copy at | |
4 | * http://www.boost.org/LICENSE_1_0.txt) | |
5 | * | |
6 | * See http://www.boost.org/libs/poly_collection for library home page. | |
7 | */ | |
8 | ||
9 | #include "test_emplacement.hpp" | |
10 | ||
11 | #include <boost/core/lightweight_test.hpp> | |
12 | #include "any_types.hpp" | |
13 | #include "base_types.hpp" | |
14 | #include "function_types.hpp" | |
15 | #include "test_utilities.hpp" | |
16 | ||
17 | using namespace test_utilities; | |
18 | ||
19 | template<typename PolyCollection,typename ValueFactory,typename... Types> | |
20 | void test_emplacement() | |
21 | { | |
22 | { | |
23 | using type=first_of< | |
24 | constraints< | |
25 | is_constructible_from_int,is_not_copy_constructible, | |
26 | is_not_copy_assignable, | |
27 | is_equality_comparable | |
28 | >, | |
29 | Types... | |
30 | >; | |
31 | using iterator=typename PolyCollection::iterator; | |
32 | using local_base_iterator=typename PolyCollection::local_base_iterator; | |
33 | using local_iterator= | |
34 | typename PolyCollection::template local_iterator<type>; | |
35 | ||
36 | PolyCollection p; | |
37 | ||
38 | iterator it=p.template emplace<type>(4); | |
39 | BOOST_TEST(*p.template begin<type>()==type{4}); | |
40 | BOOST_TEST(&*it==&*p.begin(typeid(type))); | |
41 | ||
42 | iterator it2=p.template emplace_hint<type>(it,3); | |
43 | BOOST_TEST(*p.template begin<type>()==type{3}); | |
44 | BOOST_TEST(&*it2==&*p.begin(typeid(type))); | |
45 | ||
46 | iterator it3=p.template emplace_hint<type>(p.cend(),5); | |
47 | BOOST_TEST(*(p.template end<type>()-1)==type{5}); | |
48 | BOOST_TEST(&*it3==&*(p.end(typeid(type))-1)); | |
49 | ||
50 | local_base_iterator lbit= | |
51 | p.template emplace_pos<type>(p.begin(typeid(type)),2); | |
52 | BOOST_TEST(*static_cast<local_iterator>(lbit)==type{2}); | |
53 | BOOST_TEST(lbit==p.begin(typeid(type))); | |
54 | ||
55 | local_base_iterator lbit2= | |
56 | p.template emplace_pos<type>(p.cend(typeid(type)),6); | |
57 | BOOST_TEST(*static_cast<local_iterator>(lbit2)==type{6}); | |
58 | BOOST_TEST(lbit2==p.end(typeid(type))-1); | |
59 | ||
60 | local_iterator lit=p.emplace_pos(p.template begin<type>(),1); | |
61 | BOOST_TEST(*lit==type{1}); | |
62 | BOOST_TEST(lit==p.template begin<type>()); | |
63 | ||
64 | local_iterator lit2=p.emplace_pos(p.template cend<type>(),7); | |
65 | BOOST_TEST(*lit2==type{7}); | |
66 | BOOST_TEST(lit2==p.template end<type>()-1); | |
67 | } | |
68 | { | |
69 | using type=first_of< | |
70 | constraints<is_default_constructible>, | |
71 | Types... | |
72 | >; | |
73 | ||
74 | PolyCollection p; | |
75 | ||
76 | p.template emplace<type>(); | |
77 | p.template emplace_hint<type>(p.begin()); | |
78 | p.template emplace_hint<type>(p.cend()); | |
79 | p.template emplace_pos<type>(p.begin(typeid(type))); | |
80 | p.template emplace_pos<type>(p.cend(typeid(type))); | |
81 | p.emplace_pos(p.template begin<type>()); | |
82 | p.emplace_pos(p.template cend<type>()); | |
83 | BOOST_TEST(p.size()==7); | |
84 | } | |
85 | { | |
86 | using type=first_of< | |
87 | constraints<is_not_copy_constructible>, | |
88 | Types... | |
89 | >; | |
90 | ||
91 | PolyCollection p; | |
92 | ValueFactory v; | |
93 | ||
94 | p.template emplace<type>(v.template make<type>()); | |
95 | p.template emplace_hint<type>(p.begin(),v.template make<type>()); | |
96 | p.template emplace_hint<type>(p.cend(),v.template make<type>()); | |
97 | p.template emplace_pos<type>( | |
98 | p.begin(typeid(type)),v.template make<type>()); | |
99 | p.template emplace_pos<type>( | |
100 | p.cend(typeid(type)),v.template make<type>()); | |
101 | p.emplace_pos(p.template begin<type>(),v.template make<type>()); | |
102 | p.emplace_pos(p.template cend<type>(),v.template make<type>()); | |
103 | BOOST_TEST(p.size()==7); | |
104 | } | |
105 | } | |
106 | ||
107 | void test_emplacement() | |
108 | { | |
109 | test_emplacement< | |
110 | any_types::collection,auto_increment, | |
111 | any_types::t1,any_types::t2,any_types::t3, | |
112 | any_types::t4,any_types::t5>(); | |
113 | test_emplacement< | |
114 | base_types::collection,auto_increment, | |
115 | base_types::t1,base_types::t2,base_types::t3, | |
116 | base_types::t4,base_types::t5>(); | |
117 | test_emplacement< | |
118 | function_types::collection,auto_increment, | |
119 | function_types::t1,function_types::t2,function_types::t3, | |
120 | function_types::t4,function_types::t5>(); | |
121 | } |