issue_90.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/at.hpp>
  5. #include <boost/hana/at_key.hpp>
  6. #include <boost/hana/back.hpp>
  7. #include <boost/hana/front.hpp>
  8. #include <boost/hana/integral_constant.hpp>
  9. #include <boost/hana/tuple.hpp>
  10. #include <utility>
  11. namespace hana = boost::hana;
  12. template <typename T>
  13. T const& cref(T& t) { return t; }
  14. // a non-movable, non-copyable type
  15. struct RefOnly {
  16. RefOnly() = default;
  17. RefOnly(RefOnly const&) = delete;
  18. RefOnly(RefOnly&&) = delete;
  19. };
  20. template <int i>
  21. struct RefOnly_i : hana::int_<i> {
  22. RefOnly_i() = default;
  23. RefOnly_i(RefOnly_i const&) = delete;
  24. RefOnly_i(RefOnly_i&&) = delete;
  25. };
  26. int main() {
  27. hana::tuple<RefOnly> t;
  28. // Make sure that we return the proper reference types from `at`.
  29. {
  30. RefOnly&& r1 = hana::at_c<0>(std::move(t));
  31. RefOnly& r2 = hana::at_c<0>(t);
  32. RefOnly const& r3 = hana::at_c<0>(cref(t));
  33. (void)r1; (void)r2; (void)r3;
  34. }
  35. // Make sure we return the proper reference types from `front`.
  36. {
  37. RefOnly&& r1 = hana::front(std::move(t));
  38. RefOnly& r2 = hana::front(t);
  39. RefOnly const& r3 = hana::front(cref(t));
  40. (void)r1; (void)r2; (void)r3;
  41. }
  42. // Make sure we return the proper reference types from `back`.
  43. {
  44. RefOnly&& r1 = hana::back(std::move(t));
  45. RefOnly& r2 = hana::back(t);
  46. RefOnly const& r3 = hana::back(cref(t));
  47. (void)r1; (void)r2; (void)r3;
  48. }
  49. // Make sure we return the proper reference types from `at_key`.
  50. {
  51. hana::tuple<RefOnly_i<3>> t{};
  52. RefOnly_i<3>& r1 = hana::at_key(t, RefOnly_i<3>{});
  53. RefOnly_i<3> const& r2 = hana::at_key(cref(t), RefOnly_i<3>{});
  54. RefOnly_i<3>&& r3 = hana::at_key(std::move(t), RefOnly_i<3>{});
  55. (void)r1; (void)r2; (void)r3;
  56. }
  57. }