File indexing completed on 2025-01-18 09:42:19
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_MP_DETAIL_EMPTY_VALUE_HPP
0008 #define BOOST_MP_DETAIL_EMPTY_VALUE_HPP
0009
0010 #include <utility>
0011 #include <boost/multiprecision/detail/standalone_config.hpp>
0012
0013 #if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 40700)
0014 #define BOOST_DETAIL_EMPTY_VALUE_BASE
0015 #elif defined(BOOST_INTEL) && defined(_MSC_VER) && (_MSC_VER >= 1800)
0016 #define BOOST_DETAIL_EMPTY_VALUE_BASE
0017 #elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1800)
0018 #define BOOST_DETAIL_EMPTY_VALUE_BASE
0019 #elif defined(BOOST_CLANG) && !defined(__CUDACC__)
0020 #if __has_feature(is_empty) && __has_feature(is_final)
0021 #define BOOST_DETAIL_EMPTY_VALUE_BASE
0022 #endif
0023 #endif
0024
0025 namespace boost { namespace multiprecision { namespace detail {
0026
0027 template <typename T>
0028 struct use_empty_value_base
0029 {
0030 #if defined(BOOST_DETAIL_EMPTY_VALUE_BASE)
0031 static constexpr bool value = __is_empty(T) && !__is_final(T);
0032 #else
0033 static constexpr bool value = false;
0034 #endif
0035 };
0036
0037 struct empty_init_t {};
0038
0039 namespace empty_impl {
0040
0041 template <typename T, unsigned N = 0,
0042 bool E = boost::multiprecision::detail::use_empty_value_base<T>::value>
0043 class empty_value
0044 {
0045 private:
0046 T value_;
0047
0048 public:
0049 using type = T;
0050
0051 empty_value() = default;
0052 explicit empty_value(boost::multiprecision::detail::empty_init_t) : value_ {} {}
0053
0054 template <typename U, typename... Args>
0055 empty_value(boost::multiprecision::detail::empty_init_t, U&& value, Args&&... args) :
0056 value_ {std::forward<U>(value), std::forward<Args>(args)...} {}
0057
0058 const T& get() const noexcept { return value_; }
0059 T& get() noexcept { return value_; }
0060 };
0061
0062 template <typename T, unsigned N>
0063 class empty_value<T, N, true> : T
0064 {
0065 public:
0066 using type = T;
0067
0068 empty_value() = default;
0069 explicit empty_value(boost::multiprecision::detail::empty_init_t) : T{} {}
0070
0071 template <typename U, typename... Args>
0072 empty_value(boost::multiprecision::detail::empty_init_t, U&& value, Args&&... args) :
0073 T{std::forward<U>(value), std::forward<Args>(args)...} {}
0074
0075 const T& get() const noexcept { return *this; }
0076 T& get() noexcept { return *this; }
0077 };
0078
0079 }
0080
0081 using empty_impl::empty_value;
0082
0083 BOOST_INLINE_CONSTEXPR empty_init_t empty_init = empty_init_t();
0084
0085 }}}
0086
0087 #endif