Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0007 #ifndef BOOST_PFR_DETAIL_CORE17_HPP
0008 #define BOOST_PFR_DETAIL_CORE17_HPP
0009 #pragma once
0010 
0011 #include <boost/pfr/detail/core17_generated.hpp>
0012 #include <boost/pfr/detail/fields_count.hpp>
0013 #include <boost/pfr/detail/for_each_field_impl.hpp>
0014 #include <boost/pfr/detail/rvalue_t.hpp>
0015 
0016 namespace boost { namespace pfr { namespace detail {
0017 
0018 #ifndef _MSC_VER // MSVC fails to compile the following code, but compiles the structured bindings in core17_generated.hpp
0019 struct do_not_define_std_tuple_size_for_me {
0020     bool test1 = true;
0021 };
0022 
0023 template <class T>
0024 constexpr bool do_structured_bindings_work() noexcept { // ******************************************* IN CASE OF ERROR READ THE FOLLOWING LINES IN boost/pfr/detail/core17.hpp FILE:
0025     T val{};
0026     auto& [a] = val; // ******************************************* IN CASE OF ERROR READ THE FOLLOWING LINES IN boost/pfr/detail/core17.hpp FILE:
0027 
0028     /****************************************************************************
0029     *
0030     * It looks like your compiler or Standard Library can not handle C++17
0031     * structured bindings.
0032     *
0033     * Workaround: Define BOOST_PFR_USE_CPP17 to 0
0034     * It will disable the C++17 features for Boost.PFR library.
0035     *
0036     * Sorry for the inconvenience caused.
0037     *
0038     ****************************************************************************/
0039 
0040     return a;
0041 }
0042 
0043 static_assert(
0044     do_structured_bindings_work<do_not_define_std_tuple_size_for_me>(),
0045     "====================> Boost.PFR: Your compiler can not handle C++17 structured bindings. Read the above comments for workarounds."
0046 );
0047 #endif // #ifndef _MSC_VER
0048 
0049 template <class T>
0050 constexpr auto tie_as_tuple(T& val) noexcept {
0051   static_assert(
0052     !std::is_union<T>::value,
0053     "====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
0054   );
0055   typedef size_t_<boost::pfr::detail::fields_count<T>()> fields_count_tag;
0056   return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{});
0057 }
0058 
0059 template <class T, class F, std::size_t... I>
0060 constexpr void for_each_field_dispatcher(T& t, F&& f, std::index_sequence<I...>) {
0061     static_assert(
0062         !std::is_union<T>::value,
0063         "====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
0064     );
0065     std::forward<F>(f)(
0066         detail::tie_as_tuple(t)
0067     );
0068 }
0069 
0070 }}} // namespace boost::pfr::detail
0071 
0072 #endif // BOOST_PFR_DETAIL_CORE17_HPP