]>
Commit | Line | Data |
---|---|---|
1e59de90 | 1 | // Copyright (c) 2016-2022 Antony Polukhin |
20effc67 TL |
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 | ||
6 | #ifndef BOOST_PFR_DETAIL_FOR_EACH_FIELD_IMPL_HPP | |
7 | #define BOOST_PFR_DETAIL_FOR_EACH_FIELD_IMPL_HPP | |
8 | #pragma once | |
9 | ||
10 | #include <boost/pfr/detail/config.hpp> | |
11 | ||
12 | #include <utility> // metaprogramming stuff | |
13 | ||
14 | #include <boost/pfr/detail/sequence_tuple.hpp> | |
15 | #include <boost/pfr/detail/rvalue_t.hpp> | |
16 | ||
17 | namespace boost { namespace pfr { namespace detail { | |
18 | ||
19 | template <std::size_t Index> | |
20 | using size_t_ = std::integral_constant<std::size_t, Index >; | |
21 | ||
22 | template <class T, class F, class I, class = decltype(std::declval<F>()(std::declval<T>(), I{}))> | |
23 | void for_each_field_impl_apply(T&& v, F&& f, I i, long) { | |
24 | std::forward<F>(f)(std::forward<T>(v), i); | |
25 | } | |
26 | ||
27 | template <class T, class F, class I> | |
28 | void for_each_field_impl_apply(T&& v, F&& f, I /*i*/, int) { | |
29 | std::forward<F>(f)(std::forward<T>(v)); | |
30 | } | |
31 | ||
32 | template <class T, class F, std::size_t... I> | |
33 | void for_each_field_impl(T& t, F&& f, std::index_sequence<I...>, std::false_type /*move_values*/) { | |
1e59de90 | 34 | const int v[] = {0, ( |
20effc67 TL |
35 | detail::for_each_field_impl_apply(sequence_tuple::get<I>(t), std::forward<F>(f), size_t_<I>{}, 1L), |
36 | 0 | |
37 | )...}; | |
38 | (void)v; | |
39 | } | |
40 | ||
41 | ||
42 | template <class T, class F, std::size_t... I> | |
43 | void for_each_field_impl(T& t, F&& f, std::index_sequence<I...>, std::true_type /*move_values*/) { | |
1e59de90 | 44 | const int v[] = {0, ( |
20effc67 TL |
45 | detail::for_each_field_impl_apply(sequence_tuple::get<I>(std::move(t)), std::forward<F>(f), size_t_<I>{}, 1L), |
46 | 0 | |
47 | )...}; | |
48 | (void)v; | |
49 | } | |
50 | ||
51 | }}} // namespace boost::pfr::detail | |
52 | ||
53 | ||
54 | #endif // BOOST_PFR_DETAIL_FOR_EACH_FIELD_IMPL_HPP |