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_CONSTEXPR_MOVE_ONLY_HPP 6 #define TEST_SUPPORT_CONSTEXPR_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 <utility> 13 14 15 // A move-only type that's also a literal type. It is also Comparable and 16 // Hashable so it can be used in associative containers. 17 template <int i> 18 struct ConstexprMoveOnly { ConstexprMoveOnlyConstexprMoveOnly19 constexpr ConstexprMoveOnly() { } 20 constexpr ConstexprMoveOnly(ConstexprMoveOnly const&) = delete; 21 constexpr ConstexprMoveOnly& operator=(ConstexprMoveOnly const&) = delete; ConstexprMoveOnlyConstexprMoveOnly22 constexpr ConstexprMoveOnly(ConstexprMoveOnly&&) { } 23 }; 24 25 template <int i, int j> operator ==(ConstexprMoveOnly<i> const &,ConstexprMoveOnly<j> const &)26constexpr auto operator==(ConstexprMoveOnly<i> const&, ConstexprMoveOnly<j> const&) 27 { return boost::hana::bool_c<i == j>; } 28 29 template <int i, int j> operator !=(ConstexprMoveOnly<i> const &,ConstexprMoveOnly<j> const &)30constexpr auto operator!=(ConstexprMoveOnly<i> const&, ConstexprMoveOnly<j> const&) 31 { return boost::hana::bool_c<i != j>; } 32 33 namespace boost { namespace hana { 34 template <int i> 35 struct hash_impl<ConstexprMoveOnly<i>> { applyboost::hana::hash_impl36 static constexpr auto apply(ConstexprMoveOnly<i> const&) 37 { return hana::type_c<ConstexprMoveOnly<i>>; }; 38 }; 39 }} 40 41 #endif // !TEST_SUPPORT_CONSTEXPR_MOVE_ONLY_HPP 42