summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/test/map/cnstr.copy.cpp
blob: 881de02bb86a5ac7486cc3b648e9c1db0b2c1062 (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
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)

#include <boost/hana/assert.hpp>
#include <boost/hana/bool.hpp>
#include <boost/hana/equal.hpp>
#include <boost/hana/fwd/hash.hpp>
#include <boost/hana/integral_constant.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/type.hpp>

#include <string>
#include <type_traits>
namespace hana = boost::hana;


struct NoCopy {
    NoCopy() = default;
    NoCopy(NoCopy const&) = delete;
    friend auto operator==(NoCopy const&, NoCopy const&) { return hana::true_c; }
    friend auto operator!=(NoCopy const&, NoCopy const&) { return hana::false_c; }
};

// Note: It is also useful to check with a non-empty class, because that
//       triggers different instantiations due to EBO.
struct NoCopy_nonempty {
    NoCopy_nonempty() = default;
    NoCopy_nonempty(NoCopy_nonempty const&) = delete;
    int i;
    friend auto operator==(NoCopy_nonempty const&, NoCopy_nonempty const&) { return hana::true_c; }
    friend auto operator!=(NoCopy_nonempty const&, NoCopy_nonempty const&) { return hana::false_c; }
};

namespace boost { namespace hana {
    template <>
    struct hash_impl<NoCopy> {
        static constexpr auto apply(NoCopy const&)
        { return hana::type_c<NoCopy>; };
    };

    template <>
    struct hash_impl<NoCopy_nonempty> {
        static constexpr auto apply(NoCopy_nonempty const&)
        { return hana::type_c<NoCopy_nonempty>; };
    };
}}


int main() {
    {
        auto t0 = hana::make_map();
        auto t_implicit = t0;
        auto t_explicit(t0);

        (void)t_explicit;
        (void)t_implicit;
    }
    {
        auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, hana::int_c<20>));
        auto t_implicit = t0;
        auto t_explicit(t0);

        (void)t_implicit;
        (void)t_explicit;
    }
    {
        auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, hana::int_c<20>),
                                 hana::make_pair(hana::int_c<3>, hana::int_c<30>));
        auto t_implicit = t0;
        auto t_explicit(t0);

        (void)t_implicit;
        (void)t_explicit;
    }
    {
        auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, hana::int_c<20>),
                                 hana::make_pair(hana::int_c<3>, hana::int_c<30>),
                                 hana::make_pair(hana::type_c<void>, hana::type_c<void*>));
        auto t_implicit = t0;
        auto t_explicit(t0);

        (void)t_implicit;
        (void)t_explicit;
    }
    {
        constexpr auto t0 = hana::make_map(
            hana::make_pair(hana::int_c<2>, hana::int_c<20>),
            hana::make_pair(hana::int_c<3>, hana::int_c<30>),
            hana::make_pair(hana::type_c<void>, hana::type_c<void*>));
        constexpr auto t_implicit = t0;
        constexpr auto t_explicit(t0);

        (void)t_implicit;
        (void)t_explicit;
    }
    {
        auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, std::string{"abcdef"}));
        auto copy = t0;
        BOOST_HANA_RUNTIME_CHECK(
            copy == hana::make_map(hana::make_pair(hana::int_c<2>, std::string{"abcdef"}))
        );
    }

    {
        using Map1 = hana::map<hana::pair<NoCopy, NoCopy>>;
        Map1 map1; (void)map1;
        static_assert(!std::is_copy_constructible<Map1>::value, "");

        using Map2 = hana::map<hana::pair<NoCopy_nonempty, NoCopy_nonempty>>;
        Map2 map2; (void)map2;
        static_assert(!std::is_copy_constructible<Map2>::value, "");
    }
}