]>
Commit | Line | Data |
---|---|---|
b32b8144 | 1 | // Copyright Louis Dionne 2013-2017 |
7c673cae FG |
2 | // Distributed under the Boost Software License, Version 1.0. |
3 | // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
4 | ||
5 | #include <boost/hana/assert.hpp> | |
b32b8144 | 6 | #include <boost/hana/bool.hpp> |
7c673cae | 7 | #include <boost/hana/equal.hpp> |
b32b8144 | 8 | #include <boost/hana/fwd/hash.hpp> |
7c673cae FG |
9 | #include <boost/hana/integral_constant.hpp> |
10 | #include <boost/hana/map.hpp> | |
11 | #include <boost/hana/type.hpp> | |
12 | ||
13 | #include <string> | |
b32b8144 | 14 | #include <type_traits> |
7c673cae FG |
15 | namespace hana = boost::hana; |
16 | ||
17 | ||
b32b8144 FG |
18 | struct NoCopy { |
19 | NoCopy() = default; | |
20 | NoCopy(NoCopy const&) = delete; | |
21 | friend auto operator==(NoCopy const&, NoCopy const&) { return hana::true_c; } | |
22 | friend auto operator!=(NoCopy const&, NoCopy const&) { return hana::false_c; } | |
23 | }; | |
24 | ||
25 | // Note: It is also useful to check with a non-empty class, because that | |
26 | // triggers different instantiations due to EBO. | |
27 | struct NoCopy_nonempty { | |
28 | NoCopy_nonempty() = default; | |
29 | NoCopy_nonempty(NoCopy_nonempty const&) = delete; | |
30 | int i; | |
31 | friend auto operator==(NoCopy_nonempty const&, NoCopy_nonempty const&) { return hana::true_c; } | |
32 | friend auto operator!=(NoCopy_nonempty const&, NoCopy_nonempty const&) { return hana::false_c; } | |
33 | }; | |
34 | ||
35 | namespace boost { namespace hana { | |
36 | template <> | |
37 | struct hash_impl<NoCopy> { | |
38 | static constexpr auto apply(NoCopy const&) | |
39 | { return hana::type_c<NoCopy>; }; | |
40 | }; | |
41 | ||
42 | template <> | |
43 | struct hash_impl<NoCopy_nonempty> { | |
44 | static constexpr auto apply(NoCopy_nonempty const&) | |
45 | { return hana::type_c<NoCopy_nonempty>; }; | |
46 | }; | |
47 | }} | |
48 | ||
49 | ||
7c673cae FG |
50 | int main() { |
51 | { | |
52 | auto t0 = hana::make_map(); | |
53 | auto t_implicit = t0; | |
54 | auto t_explicit(t0); | |
55 | ||
56 | (void)t_explicit; | |
57 | (void)t_implicit; | |
58 | } | |
59 | { | |
60 | auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, hana::int_c<20>)); | |
61 | auto t_implicit = t0; | |
62 | auto t_explicit(t0); | |
63 | ||
64 | (void)t_implicit; | |
65 | (void)t_explicit; | |
66 | } | |
67 | { | |
68 | auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, hana::int_c<20>), | |
69 | hana::make_pair(hana::int_c<3>, hana::int_c<30>)); | |
70 | auto t_implicit = t0; | |
71 | auto t_explicit(t0); | |
72 | ||
73 | (void)t_implicit; | |
74 | (void)t_explicit; | |
75 | } | |
76 | { | |
77 | auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, hana::int_c<20>), | |
78 | hana::make_pair(hana::int_c<3>, hana::int_c<30>), | |
79 | hana::make_pair(hana::type_c<void>, hana::type_c<void*>)); | |
80 | auto t_implicit = t0; | |
81 | auto t_explicit(t0); | |
82 | ||
83 | (void)t_implicit; | |
84 | (void)t_explicit; | |
85 | } | |
86 | { | |
87 | constexpr auto t0 = hana::make_map( | |
88 | hana::make_pair(hana::int_c<2>, hana::int_c<20>), | |
89 | hana::make_pair(hana::int_c<3>, hana::int_c<30>), | |
90 | hana::make_pair(hana::type_c<void>, hana::type_c<void*>)); | |
91 | constexpr auto t_implicit = t0; | |
92 | constexpr auto t_explicit(t0); | |
93 | ||
94 | (void)t_implicit; | |
95 | (void)t_explicit; | |
96 | } | |
97 | { | |
98 | auto t0 = hana::make_map(hana::make_pair(hana::int_c<2>, std::string{"abcdef"})); | |
99 | auto copy = t0; | |
100 | BOOST_HANA_RUNTIME_CHECK( | |
101 | copy == hana::make_map(hana::make_pair(hana::int_c<2>, std::string{"abcdef"})) | |
102 | ); | |
103 | } | |
b32b8144 FG |
104 | |
105 | { | |
106 | using Map1 = hana::map<hana::pair<NoCopy, NoCopy>>; | |
107 | Map1 map1; | |
108 | static_assert(!std::is_copy_constructible<Map1>::value, ""); | |
109 | ||
110 | using Map2 = hana::map<hana::pair<NoCopy_nonempty, NoCopy_nonempty>>; | |
111 | Map2 map2; | |
112 | static_assert(!std::is_copy_constructible<Map2>::value, ""); | |
113 | } | |
7c673cae | 114 | } |