stdtuple.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2016-2021 Antony Polukhin
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PFR_DETAIL_STDTUPLE_HPP
  6. #define BOOST_PFR_DETAIL_STDTUPLE_HPP
  7. #pragma once
  8. #include <boost/pfr/detail/config.hpp>
  9. #include <utility> // metaprogramming stuff
  10. #include <tuple>
  11. #include <boost/pfr/detail/sequence_tuple.hpp>
  12. namespace boost { namespace pfr { namespace detail {
  13. template <class T, std::size_t... I>
  14. constexpr auto make_stdtuple_from_tietuple(const T& t, std::index_sequence<I...>) noexcept {
  15. return std::make_tuple(
  16. boost::pfr::detail::sequence_tuple::get<I>(t)...
  17. );
  18. }
  19. template <class T, std::size_t... I>
  20. constexpr auto make_stdtiedtuple_from_tietuple(const T& t, std::index_sequence<I...>) noexcept {
  21. return std::tie(
  22. boost::pfr::detail::sequence_tuple::get<I>(t)...
  23. );
  24. }
  25. template <class T, std::size_t... I>
  26. constexpr auto make_conststdtiedtuple_from_tietuple(const T& t, std::index_sequence<I...>) noexcept {
  27. return std::tuple<
  28. std::add_lvalue_reference_t<std::add_const_t<
  29. std::remove_reference_t<decltype(boost::pfr::detail::sequence_tuple::get<I>(t))>
  30. >>...
  31. >(
  32. boost::pfr::detail::sequence_tuple::get<I>(t)...
  33. );
  34. }
  35. }}} // namespace boost::pfr::detail
  36. #endif // BOOST_PFR_DETAIL_STDTUPLE_HPP