• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TEST_SUPPORT_TRACKED_MOVE_ONLY_HPP
6 #define TEST_SUPPORT_TRACKED_MOVE_ONLY_HPP
7 
8 #include <boost/hana/bool.hpp>
9 #include <boost/hana/fwd/hash.hpp>
10 #include <boost/hana/type.hpp>
11 
12 #include <support/tracked.hpp>
13 
14 #include <utility>
15 
16 
17 // A move-only type that's Tracked. It is also Comparable and Hashable so it
18 // can be used in associative containers.
19 template <int i>
20 struct TrackedMoveOnly : Tracked {
TrackedMoveOnlyTrackedMoveOnly21     TrackedMoveOnly() : Tracked(i) { }
22     TrackedMoveOnly(TrackedMoveOnly const&) = delete;
23     TrackedMoveOnly& operator=(TrackedMoveOnly const&) = delete;
TrackedMoveOnlyTrackedMoveOnly24     TrackedMoveOnly(TrackedMoveOnly&& x)
25         : Tracked(std::move(x))
26     { }
27 };
28 
29 template <int i, int j>
operator ==(TrackedMoveOnly<i> const &,TrackedMoveOnly<j> const &)30 constexpr auto operator==(TrackedMoveOnly<i> const&, TrackedMoveOnly<j> const&)
31 { return boost::hana::bool_c<i == j>; }
32 
33 template <int i, int j>
operator !=(TrackedMoveOnly<i> const &,TrackedMoveOnly<j> const &)34 constexpr auto operator!=(TrackedMoveOnly<i> const&, TrackedMoveOnly<j> const&)
35 { return boost::hana::bool_c<i != j>; }
36 
37 namespace boost { namespace hana {
38     template <int i>
39     struct hash_impl<TrackedMoveOnly<i>> {
applyboost::hana::hash_impl40         static constexpr auto apply(TrackedMoveOnly<i> const&)
41         { return hana::type_c<TrackedMoveOnly<i>>; };
42     };
43 }}
44 
45 #endif // !TEST_SUPPORT_TRACKED_MOVE_ONLY_HPP
46