Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 08:18:50

0001 // Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov.
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 // Initial implementation by Bela Schaum, https://github.com/schaumb
0008 // The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
0009 //
0010 
0011 #ifndef BOOST_PFR_DETAIL_FAKE_OBJECT_HPP
0012 #define BOOST_PFR_DETAIL_FAKE_OBJECT_HPP
0013 #pragma once
0014 
0015 #include <boost/pfr/detail/config.hpp>
0016 
0017 #ifdef __clang__
0018 #   pragma clang diagnostic push
0019 #   pragma clang diagnostic ignored "-Wundefined-internal"
0020 #   pragma clang diagnostic ignored "-Wundefined-var-template"
0021 #elif defined(__GNUC__)
0022 #   pragma GCC diagnostic push
0023 #   pragma GCC diagnostic ignored "-Wundefined-var-template"
0024 #endif
0025 
0026 namespace boost { namespace pfr { namespace detail {
0027 
0028 // This class has external linkage while T has not sure.
0029 template <class T>
0030 struct wrapper {
0031     const T value;
0032 };
0033 
0034 // This variable servers as a link-time assert.
0035 // If linker requires it, then `fake_object()` is used at runtime.
0036 template <class T>
0037 extern const wrapper<T> do_not_use_PFR_with_local_types;
0038 
0039 // For returning non default constructible types, it's exclusively used in member name retrieval.
0040 //
0041 // Neither std::declval nor boost::pfr::detail::unsafe_declval are usable there.
0042 // This takes advantage of C++20 features, while boost::pfr::detail::unsafe_declval works
0043 // with the former standards.
0044 template <class T>
0045 constexpr const T& fake_object() noexcept {
0046     return do_not_use_PFR_with_local_types<T>.value;
0047 }
0048 
0049 }}} // namespace boost::pfr::detail
0050 
0051 #ifdef __clang__
0052 #   pragma clang diagnostic push
0053 #elif defined(__GNUC__)
0054 #   pragma GCC diagnostic pop
0055 #endif
0056 #endif // BOOST_PFR_DETAIL_FAKE_OBJECT_HPP
0057