stdtuple.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2016-2024 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...>) {
  15. (void)t; // workaround for MSVC 14.1 `warning C4100: 't': unreferenced formal parameter`
  16. return std::make_tuple(
  17. boost::pfr::detail::sequence_tuple::get<I>(t)...
  18. );
  19. }
  20. template <class T, std::size_t... I>
  21. constexpr auto make_stdtiedtuple_from_tietuple(const T& t, std::index_sequence<I...>) noexcept {
  22. (void)t; // workaround for MSVC 14.1 `warning C4100: 't': unreferenced formal parameter`
  23. return std::tie(
  24. boost::pfr::detail::sequence_tuple::get<I>(t)...
  25. );
  26. }
  27. template <class T, std::size_t... I>
  28. constexpr auto make_conststdtiedtuple_from_tietuple(const T& t, std::index_sequence<I...>) noexcept {
  29. (void)t; // workaround for MSVC 14.1 `warning C4100: 't': unreferenced formal parameter`
  30. return std::tuple<
  31. std::add_lvalue_reference_t<std::add_const_t<
  32. std::remove_reference_t<decltype(boost::pfr::detail::sequence_tuple::get<I>(t))>
  33. >>...
  34. >(
  35. boost::pfr::detail::sequence_tuple::get<I>(t)...
  36. );
  37. }
  38. }}} // namespace boost::pfr::detail
  39. #endif // BOOST_PFR_DETAIL_STDTUPLE_HPP