diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:12:59 +0900 |
commit | b8cf34c691623e4ec329053cbbf68522a855882d (patch) | |
tree | 34da08632a99677f6b79ecb65e5b655a5b69a67f /boost/hof/detail/static_const_var.hpp | |
parent | 3fdc3e5ee96dca5b11d1694975a65200787eab86 (diff) | |
download | boost-upstream/1.67.0.tar.gz boost-upstream/1.67.0.tar.bz2 boost-upstream/1.67.0.zip |
Imported Upstream version 1.67.0upstream/1.67.0
Diffstat (limited to 'boost/hof/detail/static_const_var.hpp')
-rw-r--r-- | boost/hof/detail/static_const_var.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/boost/hof/detail/static_const_var.hpp b/boost/hof/detail/static_const_var.hpp new file mode 100644 index 0000000000..553bd23294 --- /dev/null +++ b/boost/hof/detail/static_const_var.hpp @@ -0,0 +1,68 @@ +/*============================================================================= + Copyright (c) 2015 Paul Fultz II + static_const_var.h + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ + +#ifndef BOOST_HOF_GUARD_STATIC_CONST_H +#define BOOST_HOF_GUARD_STATIC_CONST_H + +#include <boost/hof/detail/intrinsics.hpp> + +namespace boost { namespace hof { namespace detail { + +template<class T> +struct static_const_storage +{ + static constexpr T value = T(); +}; + +template<class T> +constexpr T static_const_storage<T>::value; + +struct static_const_var_factory +{ + constexpr static_const_var_factory() + {} + + template<class T> + constexpr const T& operator=(const T&) const + { + static_assert(BOOST_HOF_IS_DEFAULT_CONSTRUCTIBLE(T), "Static const variable must be default constructible"); + return static_const_storage<T>::value; + } +}; +} + +template<class T> +constexpr const T& static_const_var() +{ + return detail::static_const_storage<T>::value; +} + + +}} // namespace boost::hof + +#if BOOST_HOF_HAS_RELAXED_CONSTEXPR || defined(_MSC_VER) +#define BOOST_HOF_STATIC_CONSTEXPR const constexpr +#else +#define BOOST_HOF_STATIC_CONSTEXPR static constexpr +#endif + +#if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7 +#define BOOST_HOF_STATIC_AUTO_REF extern __attribute__((weak)) constexpr auto +#else +#define BOOST_HOF_STATIC_AUTO_REF static constexpr auto& +#endif + +// On gcc 4.6 use weak variables +#if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7 +#define BOOST_HOF_STATIC_CONST_VAR(name) extern __attribute__((weak)) constexpr auto name +#else +#define BOOST_HOF_STATIC_CONST_VAR(name) static constexpr auto& name = boost::hof::detail::static_const_var_factory() +#endif + +#define BOOST_HOF_DECLARE_STATIC_VAR(name, ...) BOOST_HOF_STATIC_CONST_VAR(name) = __VA_ARGS__{} + +#endif |