• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2004 Angus Leeming
3     Copyright (c) 2017 Kohei Takahashi
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(CONTAINER_TESTS_HPP)
9 #define CONTAINER_TESTS_HPP
10 
11 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/phoenix/core.hpp>
13 #include <boost/phoenix/stl/container/container.hpp>
14 
15 #include <iostream>
16 #include <typeinfo>
17 #include <deque>
18 #include <list>
19 #include <map>
20 #include <set>
21 #include <vector>
22 #include <utility>
23 #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP
24 #include <unordered_map>
25 #endif
26 #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
27 #include <unordered_set>
28 #endif
29 
30 #ifdef BOOST_MSVC
31 #pragma warning(disable : 4800)
32 #endif
33 
34 using std::cerr;
35 namespace phx = boost::phoenix;
36 
37 template <typename T> inline T const build_assoc();
38 
39 std::deque<int> const build_deque();
40 std::list<int> const build_list();
41 std::map<int, int> const build_map();
42 std::multimap<int, int> const build_multimap();
43 std::vector<int> const build_vector();
44 std::set<int> const build_set();
45 std::multiset<int> const build_multiset();
build_assoc()46 template <> inline std::map<int, int> const build_assoc() { return build_map(); }
build_assoc()47 template <> inline std::multimap<int, int> const build_assoc() { return build_multimap(); }
build_assoc()48 template <> inline std::set<int> const build_assoc() { return build_set(); }
build_assoc()49 template <> inline std::multiset<int> const build_assoc() { return build_multiset(); }
50 #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP
51 std::unordered_map<int, int> const build_unordered_map();
52 std::unordered_multimap<int, int> const build_unordered_multimap();
build_assoc()53 template <> inline std::unordered_map<int, int> const build_assoc() { return build_unordered_map(); }
build_assoc()54 template <> inline std::unordered_multimap<int, int> const build_assoc() { return build_unordered_multimap(); }
55 #endif
56 #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
57 std::unordered_set<int> const build_unordered_set();
58 std::unordered_multiset<int> const build_unordered_multiset();
build_assoc()59 template <> inline std::unordered_set<int> const build_assoc() { return build_unordered_set(); }
build_assoc()60 template <> inline std::unordered_multiset<int> const build_assoc() { return build_unordered_multiset(); }
61 #endif
62 
63 inline bool
test(bool fail)64 test(bool fail)
65 {
66     BOOST_TEST(!fail);
67     return fail;
68 }
69 
70 template <typename Container>
test_assign(Container c)71 void test_assign(Container c)
72 {
73     using phx::arg_names::arg1;
74 
75     typename Container::size_type count = 2;
76     typename Container::const_iterator first = c.begin();
77     typename Container::const_iterator second = first;
78     typename Container::value_type value = *first;
79 
80     phx::assign(arg1, count, value)(c);
81 
82     // iterators may be invalidated!
83     first = c.begin();
84     second = first;
85 
86     std::advance(second, 1);
87     if (test(*first != *second)) {
88         cerr << "Failed " << typeid(Container).name() << " test_assign 1\n";
89         return;
90     }
91 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
92     // Should not --- does not, Yay! --- compile.
93     Container const const_c = c;
94     phx::assign(const_c, count, value);
95 #endif
96 }
97 
98 template <typename Container>
test_assign2(Container c)99 void test_assign2(Container c)
100 {
101     using phx::arg_names::arg1;
102     using phx::arg_names::arg2;
103     using phx::arg_names::arg3;
104 
105     Container c2 = c;
106     typename Container::const_iterator first = c2.begin();
107     typename Container::const_iterator last = c2.end();
108     typename Container::size_type size = c2.size();
109 
110     c.clear();
111     phx::assign(arg1, arg2, arg3)(c, first, last);
112     if (test(c.size() != size)) {
113         cerr << "Failed " << typeid(Container).name()
114        << " test_assign2 1\n"
115        << "size == " << c.size() << '\n';
116         return;
117     }
118 
119 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
120     // Should not --- does not, Yay! --- compile.
121     Container const const_c = c;
122     phx::assign(const_c, first, second);
123 #endif
124 }
125 
126 template <typename Container>
test_at(Container c)127 void test_at(Container c)
128 {
129     using phx::arg_names::arg1;
130     using phx::at;
131 
132     typename Container::reference r1 = at(arg1, 0)(c);
133     if (test(r1 != c.at(0))) {
134         cerr << "Failed " << typeid(Container).name() << " test_at 1\n";
135         return;
136     }
137 
138     typename Container::const_reference r2 = at(arg1, 0)(c);
139     if (test(r2 != c.at(0))) {
140         cerr << "Failed " << typeid(Container).name() << " test_at 2\n";
141         return;
142     }
143 
144     Container const const_c = c;
145 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
146     // Should not --- does not, Yay! --- compile.
147     typename Container::reference r3 = at(arg1, 0)(const_c);
148 #endif
149 
150     typename Container::const_reference r4 = at(arg1, 0)(const_c);
151     if (test(r4 != c.at(0))) {
152         cerr << "Failed " << typeid(Container).name() << " test_at 4\n";
153         return;
154     }
155 }
156 
157 template <typename Container>
test_back(Container c)158 void test_back(Container c)
159 {
160     using phx::arg_names::arg1;
161     using phx::back;
162 
163     typename Container::reference r1 = back(arg1)(c);
164     if (test(r1 != c.back())) {
165         cerr << "Failed " << typeid(Container).name() << " test_back 1\n";
166         return;
167     }
168     typename Container::const_reference r2 = back(arg1)(c);
169     if (test(r2 != c.back())) {
170         cerr << "Failed " << typeid(Container).name() << " test_back 2\n";
171         return;
172     }
173 
174     Container const const_c = c;
175 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
176     // Should not --- does not, Yay! --- compile.
177     typename Container::reference r3 = back(arg1)(const_c);
178 #endif
179 
180     typename Container::const_reference r4 = back(arg1)(const_c);
181     if (test(r4 != c.back())) {
182         cerr << "Failed " << typeid(Container).name() << " test_back 4\n";
183         return;
184     }
185 }
186 
187 template <typename Container>
test_begin(Container c)188 void test_begin(Container c)
189 {
190     using phx::arg_names::arg1;
191     using phx::begin;
192 
193     typename Container::iterator it1 = begin(arg1)(c);
194     if (test(it1 != c.begin())) {
195         cerr << "Failed " << typeid(Container).name() << " test_begin 1\n";
196         return;
197     }
198     typename Container::const_iterator it2 = begin(arg1)(c);
199     if (test(it2 != c.begin())) {
200         cerr << "Failed " << typeid(Container).name() << " test_begin 2\n";
201         return;
202     }
203 
204     Container const const_c = c;
205 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
206     // Should not --- does not, Yay! --- compile.
207     typename Container::iterator it3 = begin(arg1)(const_c);
208 #endif
209 
210     typename Container::const_iterator it4 = begin(arg1)(const_c);
211     if (test(it4 != const_c.begin())) {
212         cerr << "Failed " << typeid(Container).name() << " test_begin 4\n";
213         return;
214     }
215 }
216 
217 template <typename Container>
test_capacity(Container c)218 void test_capacity(Container c)
219 {
220     using phx::arg_names::arg1;
221     using phx::capacity;
222 
223     typename Container::size_type s1 = capacity(arg1)(c);
224     if (test(s1 != c.capacity())) {
225         cerr << "Failed " << typeid(Container).name() << " test_capacity 1\n";
226         return;
227     }
228 
229     Container const const_c = c;
230     typename Container::size_type s2 = capacity(arg1)(const_c);
231     if (test(s2 != const_c.capacity())) {
232         cerr << "Failed " << typeid(Container).name() << " test_capacity 2\n";
233         return;
234     }
235 }
236 
237 template <typename Container>
test_clear(Container c)238 void test_clear(Container c)
239 {
240     using phx::arg_names::arg1;
241     using phx::clear;
242 
243     clear(arg1)(c);
244     if (test(!c.empty())) {
245         cerr << "Failed " << typeid(Container).name() << " test_clear 1\n";
246         return;
247     }
248 
249 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
250     Container const const_c = c;
251     clear(arg1)(const_c);
252 #endif
253 }
254 
255 template <typename Container>
test_empty(Container c)256 void test_empty(Container c)
257 {
258     using phx::arg_names::arg1;
259     using phx::empty;
260 
261     typename Container::size_type s1 = empty(arg1)(c);
262     if (test(bool(s1) != c.empty())) {
263         cerr << "Failed " << typeid(Container).name() << " test_empty 1\n";
264         return;
265     }
266 
267     Container const const_c = c;
268     typename Container::size_type s2 = empty(arg1)(const_c);
269     if (test(bool(s2) != const_c.empty())) {
270         cerr << "Failed " << typeid(Container).name() << " test_empty 2\n";
271         return;
272     }
273 }
274 
275 template <typename Container>
test_end(Container c)276 void test_end(Container c)
277 {
278     using phx::arg_names::arg1;
279     using phx::end;
280 
281     typename Container::iterator it1 = end(arg1)(c);
282     if (test(it1 != c.end())) {
283         cerr << "Failed " << typeid(Container).name() << " test_end 1\n";
284         return;
285     }
286     typename Container::const_iterator it2 = end(arg1)(c);
287     if (test(it2 != c.end())) {
288         cerr << "Failed " << typeid(Container).name() << " test_end 2\n";
289         return;
290     }
291 
292     Container const const_c = c;
293 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
294     // Should not --- does not, Yay! --- compile.
295     typename Container::iterator it3 = end(arg1)(const_c);
296 #endif
297 
298     typename Container::const_iterator it4 = end(arg1)(const_c);
299     if (test(it4 != const_c.end())) {
300         cerr << "Failed " << typeid(Container).name() << " test_end 4\n";
301         return;
302     }
303 }
304 
305 template <typename Container>
test_erase(Container c)306 void test_erase(Container c)
307 {
308     using phx::arg_names::arg1;
309     using phx::arg_names::arg2;
310     using phx::arg_names::arg3;
311     using phx::erase;
312 
313     Container const const_c = c;
314 
315     typename Container::size_type size = c.size();
316     typename Container::iterator c_begin = c.begin();
317     erase(arg1, arg2)(c, c_begin);
318     if (test(c.size() + 1 != size)) {
319         cerr << "Failed " << typeid(Container).name() << " test_erase 1\n";
320         return;
321     }
322 
323     c_begin = c.begin();
324     typename Container::iterator c_end = c.end();
325     erase(arg1, arg2, arg3)(c, c_begin, c_end);
326     if (test(!c.empty())) {
327         cerr << "Failed " << typeid(Container).name() << " test_erase 2\n";
328         return;
329     }
330 
331 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
332     erase(arg1, const_c.begin())(const_c);
333     erase(arg1, const_c.begin(), const_c.end())(const_c);
334 #endif
335 }
336 
337 template <typename Container>
test_map_erase(Container c)338 void test_map_erase(Container c)
339 {
340     test_erase(c);
341     if (boost::report_errors() != 0)
342       return;
343 
344     using phx::arg_names::arg1;
345     using phx::arg_names::arg2;
346     using phx::erase;
347 
348     typename Container::value_type const value = *c.begin();
349     typename Container::key_type const key = value.first;
350     typename Container::size_type const removed =
351         erase(arg1, arg2)(c, key);
352     if (test(removed != 1)) {
353         cerr << "Failed " << typeid(Container).name() << " test_map_erase 1\n";
354         return;
355     }
356 }
357 
358 template <typename Container>
test_set_erase(Container c)359 void test_set_erase(Container c)
360 {
361     test_erase(c);
362     if (boost::report_errors() != 0)
363       return;
364 
365     using phx::arg_names::arg1;
366     using phx::arg_names::arg2;
367     using phx::erase;
368 
369     typename Container::value_type const value = *c.begin();
370     typename Container::key_type const key = value;
371     typename Container::size_type const removed =
372         erase(arg1, arg2)(c, key);
373     if (test(removed != 1)) {
374         cerr << "Failed " << typeid(Container).name() << " test_set_erase 1\n";
375         return;
376     }
377 }
378 
379 template <typename Container>
test_front(Container c)380 void test_front(Container c)
381 {
382     using phx::arg_names::arg1;
383     using phx::front;
384 
385     typename Container::reference r1 = front(arg1)(c);
386     if (test(r1 != c.front())) {
387         cerr << "Failed " << typeid(Container).name() << " test_front 1\n";
388         return;
389     }
390     typename Container::const_reference r2 = front(arg1)(c);
391     if (test(r2 != c.front())) {
392         cerr << "Failed " << typeid(Container).name() << " test_front 2\n";
393         return;
394     }
395 
396     Container const const_c = c;
397 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
398     // Should not --- does not, Yay! --- compile.
399     typename Container::reference r3 = front(arg1)(const_c);
400 #endif
401 
402     typename Container::const_reference r4 = front(arg1)(const_c);
403     if (test(r4 != c.front())) {
404         cerr << "Failed " << typeid(Container).name() << " test_front 4\n";
405         return;
406     }
407 }
408 
409 template <typename Container>
test_get_allocator(Container c)410 void test_get_allocator(Container c)
411 {
412     using phx::arg_names::arg1;
413     using phx::get_allocator;
414 
415     Container const const_c = c;
416 
417     typename Container::allocator_type a1 = get_allocator(arg1)(c);
418     if (test(a1 != c.get_allocator())) {
419         cerr << "Failed " << typeid(Container).name() << " test_get_allocator 1\n";
420         return;
421     }
422 
423     typename Container::allocator_type a2 = get_allocator(arg1)(const_c);
424     if (test(a2 != const_c.get_allocator())) {
425         cerr << "Failed " << typeid(Container).name() << " test_get_allocator 2\n";
426         return;
427     }
428 }
429 
430 template <typename Container>
test_insert(Container c)431 void test_insert(Container c)
432 {
433     using phx::arg_names::arg1;
434     using phx::insert;
435 
436     typename Container::value_type const value = *c.begin();
437     typename Container::iterator it = insert(arg1, c.begin(), value)(c);
438     if (test(it != c.begin() || *it != *(++it))) {
439         cerr << "Failed " << typeid(Container).name() << " test_insert 1\n";
440         return;
441     }
442 
443     typename Container::size_type size = c.size();
444     insert(arg1, c.begin(), 3, value)(c);
445     if (test(c.size() != size + 3)) {
446         cerr << "Failed " << typeid(Container).name() << " test_insert 2\n";
447         return;
448     }
449 
450     Container const const_c = c;
451     size = c.size();
452     insert(arg1, c.begin(), const_c.begin(), const_c.end())(c);
453     if (test(c.size() != 2 * size)) {
454         cerr << "Failed " << typeid(Container).name() << " test_insert 3\n";
455         return;
456     }
457 }
458 
459 template <typename Map>
test_map_insert(Map c)460 inline void test_map_insert(Map c)
461 {
462     using phx::arg_names::arg1;
463     using phx::arg_names::arg2;
464     using phx::arg_names::arg3;
465 
466     typename Map::value_type const value = *c.begin();
467     typename Map::iterator c_begin = c.begin();
468     // wrapper for
469     // iterator insert(iterator where, const value_type& val);
470     typename Map::iterator it =
471         phx::insert(arg1, arg2, arg3)(c, c_begin, value);
472 
473     if (test(it != c.begin() /*|| *it != *(++it)*/)) {
474         cerr << "Failed " << typeid(Map).name() << " test_map_insert 1\n";
475         return;
476     }
477 
478     // wrapper for
479     // pair<iterator, bool> insert(const value_type& val);
480     typename Map::value_type const value2(1400, 2200);
481     std::pair<typename Map::iterator, bool> result =
482       phx::insert(arg1, arg2)(c, value2);
483     if (test(!result.second)) {
484         cerr << "Failed " << typeid(Map).name() << " test_map_insert 2\n";
485         return;
486     }
487 
488     // wrapper for
489     // template<class InIt>
490     // void insert(InIt first, InIt last);
491     Map const const_c = build_assoc<Map>();
492     typename Map::size_type size = c.size();
493     phx::insert(arg1, const_c.begin(), const_c.end())(c);
494     if (test(c.size() != size + const_c.size())) {
495         cerr << "Failed " << typeid(Map).name() << " test_map_insert 3\n";
496         return;
497     }
498 }
499 
500 template <typename Multimap>
test_multimap_insert(Multimap c)501 inline void test_multimap_insert(Multimap c)
502 {
503     using phx::arg_names::arg1;
504     using phx::arg_names::arg2;
505     using phx::arg_names::arg3;
506 
507     typename Multimap::value_type const value = *c.begin();
508     typename Multimap::iterator c_begin = c.begin();
509     std::size_t old_size = c.size();
510     // wrapper for
511     // iterator insert(iterator where, const value_type& val);
512     typename Multimap::iterator it =
513         phx::insert(arg1, arg2, arg3)(c, c_begin, value);
514 
515     if (test(*it != value || c.size() != old_size + 1)) {
516         cerr << "Failed " << typeid(Multimap).name()
517        << " test_multimap_insert 1\n";
518         return;
519     }
520 
521     // wrapper for
522     // iterator insert(const value_type& val);
523     typename Multimap::value_type const value2(1400, 2200);
524     it = phx::insert(arg1, arg2)(c, value2);
525     if (test(it == c.end())) {
526         cerr << "Failed " << typeid(Multimap).name()
527        << " test_multimap_insert 2\n";
528         return;
529     }
530 
531     // wrapper for
532     // template<class InIt>
533     // void insert(InIt first, InIt last);
534     Multimap const const_c = build_assoc<Multimap>();
535     typename Multimap::size_type size = c.size();
536     phx::insert(arg1, const_c.begin(), const_c.end())(c);
537     if (test(c.size() != size + const_c.size())) {
538         cerr << "Failed " << typeid(Multimap).name()
539        << " test_multimap_insert 3\n";
540         return;
541     }
542 }
543 
544 template <typename Set>
test_set_insert(Set c)545 inline void test_set_insert(Set c)
546 {
547     using phx::arg_names::arg1;
548     using phx::arg_names::arg2;
549     using phx::arg_names::arg3;
550 
551     typename Set::value_type const value = *c.begin();
552     typename Set::iterator c_begin = c.begin();
553     // wrapper for
554     // iterator insert(iterator where, const value_type& val);
555     typename Set::iterator it =
556         phx::insert(arg1, arg2, arg3)(c, c_begin, value);
557 
558     if (test(it != c.begin() /*|| *it != *(++it)*/)) {
559         cerr << "Failed " << typeid(Set).name() << " test_set_insert 1\n";
560         return;
561     }
562 
563     // wrapper for
564     // pair<iterator, bool> insert(const value_type& val);
565     typename Set::value_type const value2(1400);
566     std::pair<typename Set::iterator, bool> result =
567       phx::insert(arg1, arg2)(c, value2);
568     if (test(!result.second)) {
569         cerr << "Failed " << typeid(Set).name() << " test_set_insert 2\n";
570         return;
571     }
572 
573     // wrapper for
574     // template<class InIt>
575     // void insert(InIt first, InIt last);
576     Set const const_c = build_assoc<Set>();
577     typename Set::size_type size = c.size();
578     phx::insert(arg1, const_c.begin(), const_c.end())(c);
579     if (test(c.size() != size + const_c.size())) {
580         cerr << "Failed " << typeid(Set).name() << " test_set_insert 3\n";
581         return;
582     }
583 }
584 
585 template <typename Multiset>
test_multiset_insert(Multiset c)586 inline void test_multiset_insert(Multiset c)
587 {
588     using phx::arg_names::arg1;
589     using phx::arg_names::arg2;
590     using phx::arg_names::arg3;
591 
592     typename Multiset::value_type const value = *c.begin();
593     typename Multiset::iterator c_begin = c.begin();
594     std::size_t old_size = c.size();
595     // wrapper for
596     // iterator insert(iterator where, const value_type& val);
597     typename Multiset::iterator it =
598         phx::insert(arg1, arg2, arg3)(c, c_begin, value);
599 
600     if (test(*it != value || c.size() != old_size + 1)) {
601         cerr << "Failed " << typeid(Multiset).name()
602        << " test_multiset_insert 1\n";
603         return;
604     }
605 
606     // wrapper for
607     // iterator insert(const value_type& val);
608     typename Multiset::value_type const value2(1400);
609     it = phx::insert(arg1, arg2)(c, value2);
610     if (test(it == c.end())) {
611         cerr << "Failed " << typeid(Multiset).name()
612        << " test_multiset_insert 2\n";
613         return;
614     }
615 
616     // wrapper for
617     // template<class InIt>
618     // void insert(InIt first, InIt last);
619     Multiset const const_c = build_assoc<Multiset>();
620     typename Multiset::size_type size = c.size();
621     phx::insert(arg1, const_c.begin(), const_c.end())(c);
622     if (test(c.size() != size + const_c.size())) {
623         cerr << "Failed " << typeid(Multiset).name()
624        << " test_multiset_insert 3\n";
625         return;
626     }
627 }
628 
629 template <typename Container>
test_key_comp(Container c)630 void test_key_comp(Container c)
631 {
632     using phx::arg_names::arg1;
633     using phx::key_comp;
634 
635     typename Container::key_compare comp = key_comp(arg1)(c);
636 
637     Container const const_c = c;
638     comp = key_comp(arg1)(const_c);
639 }
640 
641 template <typename Container>
test_max_size(Container c)642 void test_max_size(Container c)
643 {
644     using phx::arg_names::arg1;
645     using phx::max_size;
646 
647     Container const const_c = c;
648 
649     typename Container::size_type s1 = max_size(arg1)(c);
650     if (test(s1 != c.max_size())) {
651         cerr << "Failed " << typeid(Container).name() << " test_max_size 1\n";
652         return;
653     }
654 
655     typename Container::size_type s2 = max_size(arg1)(const_c);
656     if (test(s2 != const_c.max_size())) {
657         cerr << "Failed " << typeid(Container).name() << " test_max_size 2\n";
658         return;
659     }
660 }
661 
662 template <typename Container>
test_pop_back(Container c)663 void test_pop_back(Container c)
664 {
665     using phx::arg_names::arg1;
666     using phx::pop_back;
667 
668     Container const const_c = c;
669 
670     typename Container::size_type size = c.size();
671 
672     pop_back(arg1)(c);
673     if (test(c.size() + 1 != size)) {
674         cerr << "Failed " << typeid(Container).name() << " test_pop_back 1\n";
675         return;
676     }
677 
678 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
679     pop_back(arg1)(const_c);
680 #endif
681 }
682 
683 template <typename Container>
test_pop_front(Container c)684 void test_pop_front(Container c)
685 {
686     using phx::arg_names::arg1;
687     using phx::pop_front;
688 
689     Container const const_c = c;
690 
691     typename Container::size_type size = c.size();
692 
693     pop_front(arg1)(c);
694     if (test(c.size() + 1 != size)) {
695         cerr << "Failed " << typeid(Container).name() << " test_pop_front 1\n";
696         return;
697     }
698 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
699     pop_front(arg1)(const_c);
700 #endif
701 }
702 
703 template <typename Container>
test_push_back(Container c)704 void test_push_back(Container c)
705 {
706     using phx::arg_names::arg1;
707     using phx::arg_names::arg2;
708     using phx::push_back;
709 
710     Container const const_c = c;
711 
712     typename Container::value_type data = *c.begin();
713     typename Container::size_type size = c.size();
714     push_back(arg1, arg2)(c, data);
715     if (test(c.size() != size + 1)) {
716         cerr << "Failed " << typeid(Container).name() << " test_push_back 1\n";
717         return;
718     }
719 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
720     push_back(arg1, arg2)(const_c, data);
721 #endif
722 }
723 
724 template <typename Container>
test_push_front(Container c)725 void test_push_front(Container c)
726 {
727     using phx::arg_names::arg1;
728     using phx::arg_names::arg2;
729     using phx::push_front;
730 
731     Container const const_c = c;
732 
733     typename Container::value_type data = *c.begin();
734     typename Container::size_type size = c.size();
735     push_front(arg1, arg2)(c, data);
736     if (test(c.size() != size + 1)) {
737         cerr << "Failed " << typeid(Container).name() << " test_push_front 1\n";
738         return;
739     }
740 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
741     push_front(arg1, arg2)(const_c, data);
742 #endif
743 }
744 
745 template <typename Container>
test_rbegin(Container c)746 void test_rbegin(Container c)
747 {
748     using phx::arg_names::arg1;
749     using phx::rbegin;
750 
751     typename Container::reverse_iterator it1 = rbegin(arg1)(c);
752     typename Container::reverse_iterator it1_test = c.rbegin();
753     if (test(it1 != it1_test)) {
754         cerr << "Failed " << typeid(Container).name() << " test_rbegin 1\n";
755         return;
756     }
757     typename Container::const_reverse_iterator it2 = rbegin(arg1)(c);
758     typename Container::const_reverse_iterator it2_test = c.rbegin();
759     if (test(it2 != it2_test)) {
760         cerr << "Failed " << typeid(Container).name() << " test_rbegin 2\n";
761         return;
762     }
763 
764     Container const const_c = c;
765 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
766     // Should not --- does not, Yay! --- compile.
767     typename Container::reverse_iterator it3 = rbegin(arg1)(const_c);
768 #endif
769 
770     typename Container::const_reverse_iterator it4 = rbegin(arg1)(const_c);
771     it2_test = const_c.rbegin();
772     if (test(it4 != it2_test)) {
773         cerr << "Failed " << typeid(Container).name() << " test_rbegin 4\n";
774         return;
775     }
776 }
777 
778 template <typename Container>
test_rend(Container c)779 void test_rend(Container c)
780 {
781     using phx::arg_names::arg1;
782     using phx::rend;
783 
784     typename Container::reverse_iterator it1 = rend(arg1)(c);
785     typename Container::reverse_iterator it1_test = c.rend();
786     if (test(it1 != it1_test)) {
787         cerr << "Failed " << typeid(Container).name() << " test_rend 1\n";
788         return;
789     }
790     typename Container::const_reverse_iterator it2 = rend(arg1)(c);
791     typename Container::const_reverse_iterator it2_test = c.rend();
792     if (test(it2 != it2_test)) {
793         cerr << "Failed " << typeid(Container).name() << " test_rend 2\n";
794         return;
795     }
796 
797     Container const const_c = c;
798 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
799     // Should not --- does not, Yay! --- compile.
800     typename Container::reverse_iterator it3 = rend(arg1)(const_c);
801 #endif
802 
803     typename Container::const_reverse_iterator it4 = rend(arg1)(const_c);
804     it2_test = const_c.rend();
805     if (test(it4 != it2_test)) {
806         cerr << "Failed " << typeid(Container).name() << " test_rend 4\n";
807         return;
808     }
809 }
810 
811 template <typename Container>
test_reserve(Container c)812 void test_reserve(Container c)
813 {
814     using phx::arg_names::arg1;
815     using phx::reserve;
816 
817     Container const const_c = c;
818 
819     typename Container::size_type count = 2 * c.size();
820     reserve(arg1, count)(c);
821     if (test(c.capacity() < count)) {
822         cerr << "Failed " << typeid(Container).name() << " test_reserve 1\n";
823         return;
824     }
825 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
826     reserve(arg1, count)(const_c)(const_c);
827 #endif
828 }
829 
830 template <typename Container>
test_resize(Container c)831 void test_resize(Container c)
832 {
833     using phx::arg_names::arg1;
834     using phx::resize;
835 
836     Container const const_c = c;
837 
838     typename Container::size_type new_size = 2 * c.size();
839     resize(arg1, new_size)(c);
840     if (test(c.size() != new_size)) {
841         cerr << "Failed " << typeid(Container).name() << " test_resize 1\n";
842         return;
843     }
844 
845     new_size = 2 * c.size();
846     typename Container::value_type value = *c.begin();
847     resize(arg1, new_size, value)(c);
848     if (test(c.size() != new_size)) {
849         cerr << "Failed " << typeid(Container).name() << " test_resize 2\n";
850         return;
851     }
852 #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
853     new_size = 2 * const_c.size();
854     resize(arg1, new_size)(const_c);
855 
856     new_size = 2 * const_c.size();
857     resize(arg1, new_size, value)(const_c);
858 #endif
859 }
860 
861 template <typename Container>
test_size(Container c)862 void test_size(Container c)
863 {
864     using phx::arg_names::arg1;
865     using phx::size;
866 
867     Container const const_c = c;
868 
869     typename Container::size_type s1 = size(arg1)(c);
870     if (test(s1 != c.size())) {
871         cerr << "Failed " << typeid(Container).name() << " test_size 1\n";
872         return;
873     }
874 
875     typename Container::size_type s2 = size(arg1)(const_c);
876     if (test(s2 != const_c.size())) {
877         cerr << "Failed " << typeid(Container).name() << " test_size 2\n";
878         return;
879     }
880 }
881 
882 template <typename Container>
test_splice(Container c)883 void test_splice(Container c)
884 {
885     using phx::arg_names::arg1;
886     using phx::arg_names::arg2;
887     using phx::arg_names::arg3;
888     using phx::arg_names::arg4;
889     using phx::arg_names::arg5;
890     using phx::splice;
891 
892     typename Container::iterator c_end;
893     typename Container::iterator c2_begin;
894     typename Container::iterator c2_end;
895     typename Container::size_type size = c.size();
896 
897     Container const copy = c;
898     Container const copy2 = build_list();
899     Container c2 = copy2;
900 
901     size = c.size();
902     c_end = c.end();
903     splice(arg1, arg2, arg3)(c, c_end, c2);
904     if (test(c.size() != 2 * size)) {
905         cerr << "Failed " << typeid(Container).name() << " test_splice 1\n";
906         return;
907     }
908 
909     c = copy;
910     c_end = c.end();
911     c2 = copy2;
912     c2_begin = c2.begin();
913     size = c.size() + 1;
914     splice(arg1, arg2, arg3, arg4)(c, c_end, c2, c2_begin);
915     if (test(c.size() != size)) {
916         cerr << "Failed " << typeid(Container).name() << " test_splice 2\n";
917         return;
918     }
919 
920     c = copy;
921     c_end = c.end();
922     c2 = copy2;
923     c2_begin = c2.begin();
924     c2_end = c2.end();
925     size = c.size() + c2.size();
926     /*
927     splice(arg1, arg2, arg3, arg4, arg5)(c, c_end, c2, c2_begin, c2_end);
928     if (test(c.size() != size)) {
929         cerr << "Failed " << typeid(Container).name() << " test_splice 3\n";
930         return;
931     }
932     */
933 }
934 
935 template <typename Container>
test_value_comp(Container c)936 void test_value_comp(Container c)
937 {
938     using phx::arg_names::arg1;
939     using phx::value_comp;
940 
941     typename Container::value_compare comp = value_comp(arg1)(c);
942 
943     Container const const_c = c;
944     comp = value_comp(arg1)(const_c);
945 }
946 
947 #endif
948