From a4c4c3b3191ece1396e0a863e63634600b58a44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 6 Jun 2024 14:39:49 +0200 Subject: [PATCH] Define and use BOOST_CONTAINER_CONSTANT_VAR to support BOOST_INLINE_CONSTEXPR and static const global variables. --- include/boost/container/container_fwd.hpp | 10 ++++++---- .../container/detail/adaptive_node_pool_impl.hpp | 8 ++++---- include/boost/container/detail/allocation_type.hpp | 14 +++++++------- include/boost/container/detail/copy_move_algo.hpp | 2 +- include/boost/container/detail/pool_resource.hpp | 8 ++++---- include/boost/container/detail/workaround.hpp | 6 ++++++ include/boost/container/string.hpp | 6 +----- include/boost/container/vector.hpp | 2 +- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/include/boost/container/container_fwd.hpp b/include/boost/container/container_fwd.hpp index 0ab5ace..2525b7d 100644 --- a/include/boost/container/container_fwd.hpp +++ b/include/boost/container/container_fwd.hpp @@ -15,6 +15,8 @@ # include #endif +#include + #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif @@ -332,7 +334,7 @@ struct ordered_range_t //! Value used to tag that the input range is //! guaranteed to be ordered -static const ordered_range_t ordered_range = ordered_range_t(); +BOOST_CONTAINER_CONSTANT_VAR ordered_range_t ordered_range = ordered_range_t(); //! Type used to tag that the input range is //! guaranteed to be ordered and unique @@ -342,7 +344,7 @@ struct ordered_unique_range_t //! Value used to tag that the input range is //! guaranteed to be ordered and unique -static const ordered_unique_range_t ordered_unique_range = ordered_unique_range_t(); +BOOST_CONTAINER_CONSTANT_VAR ordered_unique_range_t ordered_unique_range = ordered_unique_range_t(); //! Type used to tag that the inserted values //! should be default initialized @@ -351,7 +353,7 @@ struct default_init_t //! Value used to tag that the inserted values //! should be default initialized -static const default_init_t default_init = default_init_t(); +BOOST_CONTAINER_CONSTANT_VAR default_init_t default_init = default_init_t(); #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED //! Type used to tag that the inserted values @@ -361,7 +363,7 @@ struct value_init_t //! Value used to tag that the inserted values //! should be value initialized -static const value_init_t value_init = value_init_t(); +BOOST_CONTAINER_CONSTANT_VAR value_init_t value_init = value_init_t(); namespace container_detail_really_deep_namespace { diff --git a/include/boost/container/detail/adaptive_node_pool_impl.hpp b/include/boost/container/detail/adaptive_node_pool_impl.hpp index 46d9ec3..119b5b6 100644 --- a/include/boost/container/detail/adaptive_node_pool_impl.hpp +++ b/include/boost/container/detail/adaptive_node_pool_impl.hpp @@ -49,10 +49,10 @@ namespace container { namespace adaptive_pool_flag { -static const unsigned int none = 0u; -static const unsigned int align_only = 1u << 0u; -static const unsigned int size_ordered = 1u << 1u; -static const unsigned int address_ordered = 1u << 2u; +BOOST_CONTAINER_CONSTANT_VAR unsigned int none = 0u; +BOOST_CONTAINER_CONSTANT_VAR unsigned int align_only = 1u << 0u; +BOOST_CONTAINER_CONSTANT_VAR unsigned int size_ordered = 1u << 1u; +BOOST_CONTAINER_CONSTANT_VAR unsigned int address_ordered = 1u << 2u; } //namespace adaptive_pool_flag{ diff --git a/include/boost/container/detail/allocation_type.hpp b/include/boost/container/detail/allocation_type.hpp index 1e8aa67..5f0d4b6 100644 --- a/include/boost/container/detail/allocation_type.hpp +++ b/include/boost/container/detail/allocation_type.hpp @@ -42,13 +42,13 @@ enum allocation_type_v typedef unsigned int allocation_type; #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED -static const allocation_type allocate_new = (allocation_type)allocate_new_v; -static const allocation_type expand_fwd = (allocation_type)expand_fwd_v; -static const allocation_type expand_bwd = (allocation_type)expand_bwd_v; -static const allocation_type shrink_in_place = (allocation_type)shrink_in_place_v; -static const allocation_type try_shrink_in_place= (allocation_type)try_shrink_in_place_v; -static const allocation_type nothrow_allocation = (allocation_type)nothrow_allocation_v; -static const allocation_type zero_memory = (allocation_type)zero_memory_v; +BOOST_CONTAINER_CONSTANT_VAR allocation_type allocate_new = (allocation_type)allocate_new_v; +BOOST_CONTAINER_CONSTANT_VAR allocation_type expand_fwd = (allocation_type)expand_fwd_v; +BOOST_CONTAINER_CONSTANT_VAR allocation_type expand_bwd = (allocation_type)expand_bwd_v; +BOOST_CONTAINER_CONSTANT_VAR allocation_type shrink_in_place = (allocation_type)shrink_in_place_v; +BOOST_CONTAINER_CONSTANT_VAR allocation_type try_shrink_in_place= (allocation_type)try_shrink_in_place_v; +BOOST_CONTAINER_CONSTANT_VAR allocation_type nothrow_allocation = (allocation_type)nothrow_allocation_v; +BOOST_CONTAINER_CONSTANT_VAR allocation_type zero_memory = (allocation_type)zero_memory_v; } //namespace container { } //namespace boost { diff --git a/include/boost/container/detail/copy_move_algo.hpp b/include/boost/container/detail/copy_move_algo.hpp index c10edf1..7c7d216 100644 --- a/include/boost/container/detail/copy_move_algo.hpp +++ b/include/boost/container/detail/copy_move_algo.hpp @@ -1111,7 +1111,7 @@ inline typename dtl::disable_if_memtransfer_copy_assignable::type boost::container::destroy_alloc_n(a, large_range_f, std::size_t(n_j - n_i)); } -static const std::size_t DeepSwapAllocNMaxStorage = std::size_t(1) << std::size_t(11); //2K bytes +BOOST_CONTAINER_CONSTANT_VAR std::size_t DeepSwapAllocNMaxStorage = std::size_t(1) << std::size_t(11); //2K bytes template 2*sizeof(void*) ? memory_resource::max_align : 2*sizeof(void*); -static const std::size_t pool_options_default_largest_required_pool_block = +BOOST_CONTAINER_CONSTANT_VAR std::size_t pool_options_default_largest_required_pool_block = pool_options_minimum_largest_required_pool_block > 4096u ? pool_options_minimum_largest_required_pool_block : 4096u; diff --git a/include/boost/container/detail/workaround.hpp b/include/boost/container/detail/workaround.hpp index 23342bb..6beb7c2 100644 --- a/include/boost/container/detail/workaround.hpp +++ b/include/boost/container/detail/workaround.hpp @@ -230,4 +230,10 @@ namespace boost { # define BOOST_CONTAINER_STATIC_ASSERT_MSG( B, Msg ) BOOST_CONTAINER_STATIC_ASSERT( B ) #endif +#if !defined(BOOST_NO_CXX17_INLINE_VARIABLES) +# define BOOST_CONTAINER_CONSTANT_VAR BOOST_INLINE_CONSTEXPR +#else +# define BOOST_CONTAINER_CONSTANT_VAR static BOOST_CONSTEXPR_OR_CONST +#endif + #endif //#ifndef BOOST_CONTAINER_DETAIL_WORKAROUND_HPP diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index aec41d6..b7eaa1a 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -469,7 +469,7 @@ class basic_string_base inline void priv_short_size(size_type sz) { typedef unsigned char uchar_type; - static const uchar_type mask = uchar_type(uchar_type(-1) >> 1U); + BOOST_STATIC_CONSTEXPR uchar_type mask = uchar_type(uchar_type(-1) >> 1U); BOOST_ASSERT( sz <= mask ); //Make -Wconversion happy this->members_.pshort_repr()->h.length = uchar_type(uchar_type(sz) & mask); @@ -3085,10 +3085,6 @@ wstring; #else -template -const typename basic_string::size_type - basic_string::npos; - template struct is_string { diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index a84383e..0914176 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -269,7 +269,7 @@ inline Pointer &get_ptr(vec_iterator &it) BOOST_NOEXCEPT_OR_NO struct initial_capacity_t {}; struct vector_uninitialized_size_t {}; -static const vector_uninitialized_size_t vector_uninitialized_size = vector_uninitialized_size_t(); +BOOST_CONTAINER_CONSTANT_VAR vector_uninitialized_size_t vector_uninitialized_size = vector_uninitialized_size_t(); struct maybe_initial_capacity_t {};