| 1 | // Copyright Louis Dionne 2013-2022 |
| 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 | #include <boost/hana/assert.hpp> |
| 6 | #include <boost/hana/core/make.hpp> |
| 7 | #include <boost/hana/first.hpp> |
| 8 | #include <boost/hana/pair.hpp> |
| 9 | #include <boost/hana/second.hpp> |
| 10 | namespace hana = boost::hana; |
| 11 | |
| 12 | |
| 13 | struct MoveOnly { |
| 14 | int data_; |
| 15 | MoveOnly(MoveOnly const&) = delete; |
| 16 | MoveOnly& operator=(MoveOnly const&) = delete; |
| 17 | MoveOnly(int data) : data_(data) { } |
| 18 | MoveOnly(MoveOnly&& x) : data_(x.data_) { x.data_ = 0; } |
| 19 | |
| 20 | MoveOnly& operator=(MoveOnly&& x) |
| 21 | { data_ = x.data_; x.data_ = 0; return *this; } |
| 22 | |
| 23 | bool operator==(const MoveOnly& x) const { return data_ == x.data_; } |
| 24 | }; |
| 25 | |
| 26 | int main() { |
| 27 | { |
| 28 | hana::pair<int, short> p = hana::make_pair(3, 4); |
| 29 | BOOST_HANA_RUNTIME_CHECK(hana::first(p) == 3); |
| 30 | BOOST_HANA_RUNTIME_CHECK(hana::second(p) == 4); |
| 31 | } |
| 32 | |
| 33 | { |
| 34 | hana::pair<MoveOnly, short> p = hana::make_pair(MoveOnly{3}, 4); |
| 35 | BOOST_HANA_RUNTIME_CHECK(hana::first(p) == MoveOnly{3}); |
| 36 | BOOST_HANA_RUNTIME_CHECK(hana::second(p) == 4); |
| 37 | } |
| 38 | |
| 39 | { |
| 40 | hana::pair<MoveOnly, short> p = hana::make_pair(3, 4); |
| 41 | BOOST_HANA_RUNTIME_CHECK(hana::first(p) == MoveOnly{3}); |
| 42 | BOOST_HANA_RUNTIME_CHECK(hana::second(p) == 4); |
| 43 | } |
| 44 | |
| 45 | { |
| 46 | constexpr hana::pair<int, short> p = hana::make_pair(3, 4); |
| 47 | static_assert(hana::first(p) == 3, "" ); |
| 48 | static_assert(hana::second(p) == 4, "" ); |
| 49 | } |
| 50 | |
| 51 | // equivalence with make<pair_tag> |
| 52 | { |
| 53 | constexpr hana::pair<int, short> p = hana::make<hana::pair_tag>(3, 4); |
| 54 | static_assert(hana::first(p) == 3, "" ); |
| 55 | static_assert(hana::second(p) == 4, "" ); |
| 56 | } |
| 57 | } |
| 58 | |