Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:37

0001 // Copyright (c) 2016-2023 Antony Polukhin
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PFR_DETAIL_FOR_EACH_FIELD_IMPL_HPP
0007 #define BOOST_PFR_DETAIL_FOR_EACH_FIELD_IMPL_HPP
0008 #pragma once
0009 
0010 #include <boost/pfr/detail/config.hpp>
0011 
0012 #include <utility>      // metaprogramming stuff
0013 
0014 #include <boost/pfr/detail/sequence_tuple.hpp>
0015 #include <boost/pfr/detail/rvalue_t.hpp>
0016 
0017 namespace boost { namespace pfr { namespace detail {
0018 
0019 template <std::size_t Index>
0020 using size_t_ = std::integral_constant<std::size_t, Index >;
0021 
0022 template <class T, class F, class I, class = decltype(std::declval<F>()(std::declval<T>(), I{}))>
0023 constexpr void for_each_field_impl_apply(T&& v, F&& f, I i, long) {
0024     std::forward<F>(f)(std::forward<T>(v), i);
0025 }
0026 
0027 template <class T, class F, class I>
0028 constexpr void for_each_field_impl_apply(T&& v, F&& f, I /*i*/, int) {
0029     std::forward<F>(f)(std::forward<T>(v));
0030 }
0031 
0032 #if !defined(__cpp_fold_expressions) || __cpp_fold_expressions < 201603
0033 template <class T, class F, std::size_t... I>
0034 constexpr void for_each_field_impl(T& t, F&& f, std::index_sequence<I...>, std::false_type /*move_values*/) {
0035      const int v[] = {0, (
0036          detail::for_each_field_impl_apply(sequence_tuple::get<I>(t), std::forward<F>(f), size_t_<I>{}, 1L),
0037          0
0038      )...};
0039      (void)v;
0040 }
0041 
0042 
0043 template <class T, class F, std::size_t... I>
0044 constexpr void for_each_field_impl(T& t, F&& f, std::index_sequence<I...>, std::true_type /*move_values*/) {
0045      const int v[] = {0, (
0046          detail::for_each_field_impl_apply(sequence_tuple::get<I>(std::move(t)), std::forward<F>(f), size_t_<I>{}, 1L),
0047          0
0048      )...};
0049      (void)v;
0050 }
0051 #else
0052 template <class T, class F, std::size_t... I>
0053 constexpr void for_each_field_impl(T& t, F&& f, std::index_sequence<I...>, std::false_type /*move_values*/) {
0054      (detail::for_each_field_impl_apply(sequence_tuple::get<I>(t), std::forward<F>(f), size_t_<I>{}, 1L), ...);
0055 }
0056 
0057 template <class T, class F, std::size_t... I>
0058 constexpr void for_each_field_impl(T& t, F&& f, std::index_sequence<I...>, std::true_type /*move_values*/) {
0059      (detail::for_each_field_impl_apply(sequence_tuple::get<I>(std::move(t)), std::forward<F>(f), size_t_<I>{}, 1L), ...);
0060 }
0061 #endif
0062 
0063 }}} // namespace boost::pfr::detail
0064 
0065 
0066 #endif // BOOST_PFR_DETAIL_FOR_EACH_FIELD_IMPL_HPP