summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/poly_collection/test/test_emplacement.cpp
blob: cf4acc759ebc6e2cc7a11af1c6125cd29c682a5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Copyright 2016 Joaquin M Lopez Munoz.
 * 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/poly_collection for library home page.
 */

#include "test_emplacement.hpp"

#include <boost/core/lightweight_test.hpp>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"

using namespace test_utilities;

template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_emplacement()
{
  {
    using type=first_of<
      constraints<
        is_constructible_from_int,is_not_copy_constructible,
        is_not_copy_assignable,
        is_equality_comparable
      >,
      Types...
    >;
    using iterator=typename PolyCollection::iterator;
    using local_base_iterator=typename PolyCollection::local_base_iterator;
    using local_iterator=
      typename PolyCollection::template local_iterator<type>;

    PolyCollection p;

    iterator it=p.template emplace<type>(4);
    BOOST_TEST(*p.template begin<type>()==type{4});
    BOOST_TEST(&*it==&*p.begin(typeid(type)));

    iterator it2=p.template emplace_hint<type>(it,3);
    BOOST_TEST(*p.template begin<type>()==type{3});
    BOOST_TEST(&*it2==&*p.begin(typeid(type)));

    iterator it3=p.template emplace_hint<type>(p.cend(),5);
    BOOST_TEST(*(p.template end<type>()-1)==type{5});
    BOOST_TEST(&*it3==&*(p.end(typeid(type))-1));

    local_base_iterator lbit=
      p.template emplace_pos<type>(p.begin(typeid(type)),2);
    BOOST_TEST(*static_cast<local_iterator>(lbit)==type{2});
    BOOST_TEST(lbit==p.begin(typeid(type)));

    local_base_iterator lbit2=
      p.template emplace_pos<type>(p.cend(typeid(type)),6);
    BOOST_TEST(*static_cast<local_iterator>(lbit2)==type{6});
    BOOST_TEST(lbit2==p.end(typeid(type))-1);

    local_iterator lit=p.emplace_pos(p.template begin<type>(),1);
    BOOST_TEST(*lit==type{1});
    BOOST_TEST(lit==p.template begin<type>());

    local_iterator lit2=p.emplace_pos(p.template cend<type>(),7);
    BOOST_TEST(*lit2==type{7});
    BOOST_TEST(lit2==p.template end<type>()-1);
  }
  {
    using type=first_of<
      constraints<is_default_constructible>,
      Types...
    >;

    PolyCollection p;

    p.template emplace<type>();
    p.template emplace_hint<type>(p.begin());
    p.template emplace_hint<type>(p.cend());
    p.template emplace_pos<type>(p.begin(typeid(type)));
    p.template emplace_pos<type>(p.cend(typeid(type)));
    p.emplace_pos(p.template begin<type>());
    p.emplace_pos(p.template cend<type>());
    BOOST_TEST(p.size()==7);
  }
  {
    using type=first_of<
      constraints<is_not_copy_constructible>,
      Types...
    >;

    PolyCollection p;
    ValueFactory   v;

    p.template emplace<type>(v.template make<type>());
    p.template emplace_hint<type>(p.begin(),v.template make<type>());
    p.template emplace_hint<type>(p.cend(),v.template make<type>());
    p.template emplace_pos<type>(
      p.begin(typeid(type)),v.template make<type>());
    p.template emplace_pos<type>(
      p.cend(typeid(type)),v.template make<type>());
    p.emplace_pos(p.template begin<type>(),v.template make<type>());
    p.emplace_pos(p.template cend<type>(),v.template make<type>());
    BOOST_TEST(p.size()==7);
  }
}

void test_emplacement()
{
  test_emplacement<
    any_types::collection,auto_increment,
    any_types::t1,any_types::t2,any_types::t3,
    any_types::t4,any_types::t5>();
  test_emplacement<
    base_types::collection,auto_increment,
    base_types::t1,base_types::t2,base_types::t3,
    base_types::t4,base_types::t5>();
  test_emplacement<
    function_types::collection,auto_increment,
    function_types::t1,function_types::t2,function_types::t3,
    function_types::t4,function_types::t5>();
}