| 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 | |
| 7 | #ifndef BOOST_PFR_DETAIL_TIE_FROM_STRUCTURE_TUPLE_HPP |
| 8 | #define BOOST_PFR_DETAIL_TIE_FROM_STRUCTURE_TUPLE_HPP |
| 9 | #pragma once |
| 10 | |
| 11 | #include <boost/pfr/detail/config.hpp> |
| 12 | |
| 13 | #include <boost/pfr/detail/core.hpp> |
| 14 | |
| 15 | #include <boost/pfr/detail/stdtuple.hpp> |
| 16 | #include <boost/pfr/tuple_size.hpp> |
| 17 | #include <boost/pfr/detail/make_integer_sequence.hpp> |
| 18 | |
| 19 | #include <tuple> |
| 20 | |
| 21 | namespace boost { namespace pfr { namespace detail { |
| 22 | |
| 23 | /// \brief A `std::tuple` capable of de-structuring assignment used to support |
| 24 | /// a tie of multiple lvalue references to fields of an aggregate T. |
| 25 | /// |
| 26 | /// \sa boost::pfr::tie_from_structure |
| 27 | template <typename... Elements> |
| 28 | struct tie_from_structure_tuple : std::tuple<Elements&...> { |
| 29 | using base = std::tuple<Elements&...>; |
| 30 | using base::base; |
| 31 | |
| 32 | template <typename T> |
| 33 | constexpr tie_from_structure_tuple& operator= (T const& t) { |
| 34 | base::operator=( |
| 35 | detail::make_stdtiedtuple_from_tietuple( |
| 36 | detail::tie_as_tuple(t), |
| 37 | detail::make_index_sequence<tuple_size_v<T>>())); |
| 38 | return *this; |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | }}} // namespace boost::pfr::detail |
| 43 | |
| 44 | #endif // BOOST_PFR_DETAIL_TIE_FROM_STRUCTURE_TUPLE_HPP |
| 45 | |