cnstr.trap.cpp 1.7 KB

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