tie_from_structure_tuple.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2018 Adam Butcher, Antony Polukhin
  2. // Copyright (c) 2019-2024 Antony Polukhin
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PFR_DETAIL_TIE_FROM_STRUCTURE_TUPLE_HPP
  7. #define BOOST_PFR_DETAIL_TIE_FROM_STRUCTURE_TUPLE_HPP
  8. #pragma once
  9. #include <boost/pfr/detail/config.hpp>
  10. #include <boost/pfr/detail/core.hpp>
  11. #include <boost/pfr/detail/stdtuple.hpp>
  12. #include <boost/pfr/tuple_size.hpp>
  13. #include <boost/pfr/detail/make_integer_sequence.hpp>
  14. #include <tuple>
  15. namespace boost { namespace pfr { namespace detail {
  16. /// \brief A `std::tuple` capable of de-structuring assignment used to support
  17. /// a tie of multiple lvalue references to fields of an aggregate T.
  18. ///
  19. /// \sa boost::pfr::tie_from_structure
  20. template <typename... Elements>
  21. struct tie_from_structure_tuple : std::tuple<Elements&...> {
  22. using base = std::tuple<Elements&...>;
  23. using base::base;
  24. template <typename T>
  25. constexpr tie_from_structure_tuple& operator= (T const& t) {
  26. base::operator=(
  27. detail::make_stdtiedtuple_from_tietuple(
  28. detail::tie_as_tuple(t),
  29. detail::make_index_sequence<tuple_size_v<T>>()));
  30. return *this;
  31. }
  32. };
  33. }}} // namespace boost::pfr::detail
  34. #endif // BOOST_PFR_DETAIL_TIE_FROM_STRUCTURE_TUPLE_HPP