Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 08:43:18

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