issue_90.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/ext/std/pair.hpp>
  5. #include <boost/hana/first.hpp>
  6. #include <boost/hana/second.hpp>
  7. #include <utility>
  8. namespace hana = boost::hana;
  9. template <typename T>
  10. T const& cref(T& t) { return t; }
  11. // a non-movable, non-copyable type
  12. template <int i>
  13. struct RefOnly {
  14. RefOnly() = default;
  15. RefOnly(RefOnly const&) = delete;
  16. RefOnly(RefOnly&&) = delete;
  17. };
  18. int main() {
  19. // This test makes sure that we return the proper reference types from
  20. // `first` and `second`.
  21. std::pair<RefOnly<0>, RefOnly<1>> p;
  22. {
  23. RefOnly<0>&& r1 = hana::first(std::move(p));
  24. RefOnly<0>& r2 = hana::first(p);
  25. RefOnly<0> const& r3 = hana::first(cref(p));
  26. (void)r1; (void)r2; (void)r3;
  27. }
  28. {
  29. RefOnly<1>&& r1 = hana::second(std::move(p));
  30. RefOnly<1>& r2 = hana::second(p);
  31. RefOnly<1> const& r3 = hana::second(cref(p));
  32. (void)r1; (void)r2; (void)r3;
  33. }
  34. }