cnstr.trap.cpp 1.8 KB

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