constexpr_move_only.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #ifndef TEST_SUPPORT_CONSTEXPR_MOVE_ONLY_HPP
  5. #define TEST_SUPPORT_CONSTEXPR_MOVE_ONLY_HPP
  6. #include <boost/hana/bool.hpp>
  7. #include <boost/hana/fwd/hash.hpp>
  8. #include <boost/hana/type.hpp>
  9. #include <utility>
  10. // A move-only type that's also a literal type. It is also Comparable and
  11. // Hashable so it can be used in associative containers.
  12. template <int i>
  13. struct ConstexprMoveOnly {
  14. constexpr ConstexprMoveOnly() { }
  15. constexpr ConstexprMoveOnly(ConstexprMoveOnly const&) = delete;
  16. constexpr ConstexprMoveOnly& operator=(ConstexprMoveOnly const&) = delete;
  17. constexpr ConstexprMoveOnly(ConstexprMoveOnly&&) { }
  18. };
  19. template <int i, int j>
  20. constexpr auto operator==(ConstexprMoveOnly<i> const&, ConstexprMoveOnly<j> const&)
  21. { return boost::hana::bool_c<i == j>; }
  22. template <int i, int j>
  23. constexpr auto operator!=(ConstexprMoveOnly<i> const&, ConstexprMoveOnly<j> const&)
  24. { return boost::hana::bool_c<i != j>; }
  25. namespace boost { namespace hana {
  26. template <int i>
  27. struct hash_impl<ConstexprMoveOnly<i>> {
  28. static constexpr auto apply(ConstexprMoveOnly<i> const&)
  29. { return hana::type_c<ConstexprMoveOnly<i>>; };
  30. };
  31. }}
  32. #endif // !TEST_SUPPORT_CONSTEXPR_MOVE_ONLY_HPP