1 // Copyright Louis Dionne 2013-2017
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 #ifndef BOOST_HANA_WORKAROUND_MSVC_MULTIPLECTOR_106654
24 Trap(Trap&) = default;
25 #endif
26 Trap(Trap&&) = default;
27
28 template <typename X>
TrapTrap29 Trap(X&&) {
30 static_assert(hana::detail::wrong<X>{},
31 "this constructor must not be instantiated");
32 }
33 };
34
35 template <int i, int j>
operator ==(Trap<i> const &,Trap<j> const &)36 constexpr auto operator==(Trap<i> const&, Trap<j> const&)
37 { return hana::bool_c<i == j>; }
38
39 template <int i, int j>
operator !=(Trap<i> const &,Trap<j> const &)40 constexpr auto operator!=(Trap<i> const&, Trap<j> const&)
41 { return hana::bool_c<i != j>; }
42
43 namespace boost { namespace hana {
44 template <int i>
45 struct hash_impl<Trap<i>> {
applyboost::hana::hash_impl46 static constexpr auto apply(Trap<i> const&)
47 { return hana::type_c<Trap<i>>; };
48 };
49 }}
50
main()51 int main() {
52 {
53 auto expr = hana::make_map(
54 hana::make_pair(Trap<0>{}, Trap<0>{})
55 );
56 auto implicit_copy = expr;
57 decltype(expr) explicit_copy(expr);
58
59 (void)implicit_copy;
60 (void)explicit_copy;
61 }
62 {
63 auto expr = hana::make_map(
64 hana::make_pair(Trap<0>{}, Trap<0>{})
65 );
66 auto implicit_move = std::move(expr);
67 decltype(expr) explicit_move(std::move(implicit_move));
68
69 (void)implicit_move;
70 (void)explicit_move;
71 }
72 }
73