make.cpp 1.7 KB

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