tracked_move_only.hpp 1.4 KB

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