]>
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/bool.hpp> | |
6 | #include <boost/hana/detail/wrong.hpp> | |
7 | #include <boost/hana/fwd/hash.hpp> | |
8 | #include <boost/hana/map.hpp> | |
9 | #include <boost/hana/pair.hpp> | |
10 | #include <boost/hana/type.hpp> | |
11 | ||
12 | #include <utility> | |
13 | namespace hana = boost::hana; | |
14 | ||
15 | ||
16 | // This test makes sure that we do not instantiate rogue constructors when | |
17 | // doing copies and moves | |
18 | ||
19 | template <int i> | |
20 | struct Trap { | |
21 | Trap() = default; | |
22 | Trap(Trap const&) = default; | |
23 | Trap(Trap&) = default; | |
24 | Trap(Trap&&) = default; | |
25 | ||
26 | template <typename X> | |
27 | Trap(X&&) { | |
28 | static_assert(hana::detail::wrong<X>{}, | |
29 | "this constructor must not be instantiated"); | |
30 | } | |
31 | }; | |
32 | ||
33 | template <int i, int j> | |
34 | constexpr auto operator==(Trap<i> const&, Trap<j> const&) | |
35 | { return hana::bool_c<i == j>; } | |
36 | ||
37 | template <int i, int j> | |
38 | constexpr auto operator!=(Trap<i> const&, Trap<j> const&) | |
39 | { return hana::bool_c<i != j>; } | |
40 | ||
41 | namespace boost { namespace hana { | |
42 | template <int i> | |
43 | struct hash_impl<Trap<i>> { | |
44 | static constexpr auto apply(Trap<i> const&) | |
45 | { return hana::type_c<Trap<i>>; }; | |
46 | }; | |
47 | }} | |
48 | ||
49 | int main() { | |
50 | { | |
51 | auto expr = hana::make_map( | |
52 | hana::make_pair(Trap<0>{}, Trap<0>{}) | |
53 | ); | |
54 | auto implicit_copy = expr; | |
55 | decltype(expr) explicit_copy(expr); | |
56 | ||
57 | (void)implicit_copy; | |
58 | (void)explicit_copy; | |
59 | } | |
60 | { | |
61 | auto expr = hana::make_map( | |
62 | hana::make_pair(Trap<0>{}, Trap<0>{}) | |
63 | ); | |
64 | auto implicit_move = std::move(expr); | |
65 | decltype(expr) explicit_move(std::move(implicit_move)); | |
66 | ||
67 | (void)implicit_move; | |
68 | (void)explicit_move; | |
69 | } | |
70 | } |