Back to home page

EIC code displayed by LXR

 
 

    


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

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