tie_from_structure_tuple.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2018 Adam Butcher, Antony Polukhin
  2. // Copyright (c) 2019-2025 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. #if !defined(BOOST_PFR_INTERFACE_UNIT)
  15. #include <tuple>
  16. #endif
  17. namespace boost { namespace pfr { namespace detail {
  18. /// \brief A `std::tuple` capable of de-structuring assignment used to support
  19. /// a tie of multiple lvalue references to fields of an aggregate T.
  20. ///
  21. /// \sa boost::pfr::tie_from_structure
  22. template <typename... Elements>
  23. struct tie_from_structure_tuple : std::tuple<Elements&...> {
  24. using base = std::tuple<Elements&...>;
  25. using base::base;
  26. template <typename T>
  27. constexpr tie_from_structure_tuple& operator= (T const& t) {
  28. base::operator=(
  29. detail::make_stdtiedtuple_from_tietuple(
  30. detail::tie_as_tuple(t),
  31. detail::make_index_sequence<tuple_size_v<T>>()));
  32. return *this;
  33. }
  34. };
  35. }}} // namespace boost::pfr::detail
  36. #endif // BOOST_PFR_DETAIL_TIE_FROM_STRUCTURE_TUPLE_HPP