From b8cf34c691623e4ec329053cbbf68522a855882d Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Thu, 5 Dec 2019 15:12:59 +0900 Subject: Imported Upstream version 1.67.0 --- boost/hof/detail/static_const_var.hpp | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 boost/hof/detail/static_const_var.hpp (limited to 'boost/hof/detail/static_const_var.hpp') 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 + +namespace boost { namespace hof { namespace detail { + +template +struct static_const_storage +{ + static constexpr T value = T(); +}; + +template +constexpr T static_const_storage::value; + +struct static_const_var_factory +{ + constexpr static_const_var_factory() + {} + + template + 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::value; + } +}; +} + +template +constexpr const T& static_const_var() +{ + return detail::static_const_storage::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 -- cgit v1.2.3