Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*=============================================================================
0002     Copyright (c) 2015 Paul Fultz II
0003     static_const_var.h
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 #ifndef BOOST_HOF_GUARD_STATIC_CONST_H
0009 #define BOOST_HOF_GUARD_STATIC_CONST_H
0010 
0011 #include <boost/hof/detail/intrinsics.hpp>
0012 
0013 namespace boost { namespace hof { namespace detail {
0014 
0015 template<class T>
0016 struct static_const_storage
0017 {
0018     static constexpr T value = T();
0019 };
0020 
0021 template<class T>
0022 constexpr T static_const_storage<T>::value;
0023 
0024 struct static_const_var_factory
0025 {
0026     constexpr static_const_var_factory()
0027     {}
0028 
0029     template<class T>
0030     constexpr const T& operator=(const T&) const
0031     {
0032         static_assert(BOOST_HOF_IS_DEFAULT_CONSTRUCTIBLE(T), "Static const variable must be default constructible");
0033         return static_const_storage<T>::value;
0034     }
0035 };
0036 }
0037 
0038 template<class T>
0039 constexpr const T& static_const_var()
0040 {
0041     return detail::static_const_storage<T>::value;
0042 }
0043 
0044 
0045 }} // namespace boost::hof
0046 
0047 #if BOOST_HOF_HAS_RELAXED_CONSTEXPR || defined(_MSC_VER)
0048 #define BOOST_HOF_STATIC_CONSTEXPR const constexpr
0049 #else
0050 #define BOOST_HOF_STATIC_CONSTEXPR static constexpr
0051 #endif
0052 
0053 #if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
0054 #define BOOST_HOF_STATIC_AUTO_REF extern __attribute__((weak)) constexpr auto
0055 #else
0056 #define BOOST_HOF_STATIC_AUTO_REF static constexpr auto&
0057 #endif
0058 
0059 // On gcc 4.6 use weak variables
0060 #if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
0061 #define BOOST_HOF_STATIC_CONST_VAR(name) extern __attribute__((weak)) constexpr auto name
0062 #else
0063 #define BOOST_HOF_STATIC_CONST_VAR(name) static constexpr auto& name = boost::hof::detail::static_const_var_factory()
0064 #endif
0065 
0066 #define BOOST_HOF_DECLARE_STATIC_VAR(name, ...) BOOST_HOF_STATIC_CONST_VAR(name) = __VA_ARGS__{}
0067 
0068 #endif