Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:44:22

0001 // Copyright (c) 2019-2025 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_UNSAFE_DECLVAL_HPP
0007 #define BOOST_PFR_DETAIL_UNSAFE_DECLVAL_HPP
0008 #pragma once
0009 
0010 #include <boost/pfr/detail/config.hpp>
0011 
0012 #ifdef BOOST_PFR_HAS_STD_MODULE
0013 import std;
0014 #else
0015 #include <type_traits>
0016 #endif
0017 
0018 namespace boost { namespace pfr { namespace detail {
0019 
0020 // This function serves as a link-time assert. If linker requires it, then
0021 // `unsafe_declval()` is used at runtime.
0022 void report_if_you_see_link_error_with_this_function() noexcept;
0023 
0024 // For returning non default constructible types. Do NOT use at runtime!
0025 //
0026 // GCCs std::declval may not be used in potentionally evaluated contexts,
0027 // so we reinvent it.
0028 template <class T>
0029 constexpr T unsafe_declval() noexcept {
0030     report_if_you_see_link_error_with_this_function();
0031 
0032     typename std::remove_reference<T>::type* ptr = nullptr;
0033     ptr += 42; // suppresses 'null pointer dereference' warnings
0034     return static_cast<T>(*ptr);
0035 }
0036 
0037 }}} // namespace boost::pfr::detail
0038 
0039 
0040 #endif // BOOST_PFR_DETAIL_UNSAFE_DECLVAL_HPP
0041