1 /////////////////////////////////////////////////////////////////////
2 // Copyright 2018 Glen Joseph Fernandes.
3 // Copyright 2021 Matt Borland. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
7 #ifndef BOOST_MP_DETAIL_EMPTY_VALUE_HPP
8 #define BOOST_MP_DETAIL_EMPTY_VALUE_HPP
11 #include <boost/multiprecision/detail/standalone_config.hpp>
13 #if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 40700)
14 #define BOOST_DETAIL_EMPTY_VALUE_BASE
15 #elif defined(BOOST_INTEL) && defined(_MSC_VER) && (_MSC_VER >= 1800)
16 #define BOOST_DETAIL_EMPTY_VALUE_BASE
17 #elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1800)
18 #define BOOST_DETAIL_EMPTY_VALUE_BASE
19 #elif defined(BOOST_CLANG) && !defined(__CUDACC__)
20 #if __has_feature(is_empty) && __has_feature(is_final)
21 #define BOOST_DETAIL_EMPTY_VALUE_BASE
25 namespace boost { namespace multiprecision { namespace detail {
28 struct use_empty_value_base
30 #if defined(BOOST_DETAIL_EMPTY_VALUE_BASE)
31 static constexpr bool value = __is_empty(T) && !__is_final(T);
33 static constexpr bool value = false;
37 struct empty_init_t {};
39 namespace empty_impl {
41 template <typename T, unsigned N = 0,
42 bool E = boost::multiprecision::detail::use_empty_value_base<T>::value>
51 empty_value() = default;
52 explicit empty_value(boost::multiprecision::detail::empty_init_t) : value_ {} {}
54 template <typename U, typename... Args>
55 empty_value(boost::multiprecision::detail::empty_init_t, U&& value, Args&&... args) :
56 value_ {std::forward<U>(value), std::forward<Args>(args)...} {}
58 const T& get() const noexcept { return value_; }
59 T& get() noexcept { return value_; }
62 template <typename T, unsigned N>
63 class empty_value<T, N, true> : T
68 empty_value() = default;
69 explicit empty_value(boost::multiprecision::detail::empty_init_t) : T{} {}
71 template <typename U, typename... Args>
72 empty_value(boost::multiprecision::detail::empty_init_t, U&& value, Args&&... args) :
73 T{std::forward<U>(value), std::forward<Args>(args)...} {}
75 const T& get() const noexcept { return *this; }
76 T& get() noexcept { return *this; }
79 } // Namespace empty impl
81 using empty_impl::empty_value;
83 BOOST_INLINE_CONSTEXPR empty_init_t empty_init = empty_init_t();
87 #endif // BOOST_MP_DETAIL_EMPTY_VALUE_HPP