Skip to content

Commit

Permalink
Use BOOST_STATIC_CONSTEXPR where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
igaztanaga committed Jun 5, 2024
1 parent 8217bc0 commit 0977e6b
Show file tree
Hide file tree
Showing 46 changed files with 233 additions and 230 deletions.
16 changes: 8 additions & 8 deletions include/boost/container/adaptive_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class adaptive_pool
BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version)
> self_t;

static const std::size_t nodes_per_block = NodesPerBlock;
static const std::size_t max_free_blocks = MaxFreeBlocks;
static const std::size_t overhead_percent = OverheadPercent;
static const std::size_t real_nodes_per_block = NodesPerBlock;
BOOST_STATIC_CONSTEXPR std::size_t nodes_per_block = NodesPerBlock;
BOOST_STATIC_CONSTEXPR std::size_t max_free_blocks = MaxFreeBlocks;
BOOST_STATIC_CONSTEXPR std::size_t overhead_percent = OverheadPercent;
BOOST_STATIC_CONSTEXPR std::size_t real_nodes_per_block = NodesPerBlock;

BOOST_CONTAINER_DOCIGN(BOOST_CONTAINER_STATIC_ASSERT((Version <=2)));

Expand Down Expand Up @@ -384,10 +384,10 @@ class private_adaptive_pool
BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version)
> self_t;

static const std::size_t nodes_per_block = NodesPerBlock;
static const std::size_t max_free_blocks = MaxFreeBlocks;
static const std::size_t overhead_percent = OverheadPercent;
static const std::size_t real_nodes_per_block = NodesPerBlock;
BOOST_STATIC_CONSTEXPR std::size_t nodes_per_block = NodesPerBlock;
BOOST_STATIC_CONSTEXPR std::size_t max_free_blocks = MaxFreeBlocks;
BOOST_STATIC_CONSTEXPR std::size_t overhead_percent = OverheadPercent;
BOOST_STATIC_CONSTEXPR std::size_t real_nodes_per_block = NodesPerBlock;

BOOST_CONTAINER_DOCIGN(BOOST_CONTAINER_STATIC_ASSERT((Version <=2)));

Expand Down
2 changes: 1 addition & 1 deletion include/boost/container/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class allocator
template<class T2, unsigned int Version2, unsigned int AllocationDisableMask2>
allocator& operator=(const allocator<T2, Version2, AllocationDisableMask2>&);

static const unsigned int ForbiddenMask =
BOOST_STATIC_CONSTEXPR unsigned int ForbiddenMask =
BOOST_CONTAINER_ALLOCATE_NEW | BOOST_CONTAINER_EXPAND_BWD | BOOST_CONTAINER_EXPAND_FWD ;

//The mask can't disable all the allocation types
Expand Down
12 changes: 6 additions & 6 deletions include/boost/container/allocator_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,19 @@ namespace dtl {
//supporting rvalue references
template<class Allocator>
struct is_std_allocator
{ static const bool value = false; };
{ BOOST_STATIC_CONSTEXPR bool value = false; };

template<class T>
struct is_std_allocator< std::allocator<T> >
{ static const bool value = true; };
{ BOOST_STATIC_CONSTEXPR bool value = true; };

template<class T, class Options>
struct is_std_allocator< small_vector_allocator<T, std::allocator<T>, Options > >
{ static const bool value = true; };
{ BOOST_STATIC_CONSTEXPR bool value = true; };

template<class Allocator>
struct is_not_std_allocator
{ static const bool value = !is_std_allocator<Allocator>::value; };
{ BOOST_STATIC_CONSTEXPR bool value = !is_std_allocator<Allocator>::value; };

BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(pointer)
BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(const_pointer)
Expand Down Expand Up @@ -498,7 +498,7 @@ struct allocator_traits
template <class T, class ...Args>
inline static void construct(Allocator & a, T* p, BOOST_FWD_REF(Args)... args)
{
static const bool value = ::boost::move_detail::and_
BOOST_STATIC_CONSTEXPR bool value = ::boost::move_detail::and_
< dtl::is_not_std_allocator<Allocator>
, boost::container::dtl::has_member_function_callable_with_construct
< Allocator, T*, Args... >
Expand Down Expand Up @@ -567,7 +567,7 @@ struct allocator_traits
template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
inline static void construct(Allocator &a, T *p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{\
static const bool value = ::boost::move_detail::and_ \
BOOST_STATIC_CONSTEXPR bool value = ::boost::move_detail::and_ \
< dtl::is_not_std_allocator<Allocator> \
, boost::container::dtl::has_member_function_callable_with_construct \
< Allocator, T* BOOST_MOVE_I##N BOOST_MOVE_FWD_T##N > \
Expand Down
10 changes: 5 additions & 5 deletions include/boost/container/container_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ class basic_string;
typedef basic_string <char> string;
typedef basic_string<wchar_t> wstring;

static const std::size_t ADP_nodes_per_block = 256u;
static const std::size_t ADP_max_free_blocks = 2u;
static const std::size_t ADP_overhead_percent = 1u;
static const std::size_t ADP_only_alignment = 0u;
BOOST_STATIC_CONSTEXPR std::size_t ADP_nodes_per_block = 256u;
BOOST_STATIC_CONSTEXPR std::size_t ADP_max_free_blocks = 2u;
BOOST_STATIC_CONSTEXPR std::size_t ADP_overhead_percent = 1u;
BOOST_STATIC_CONSTEXPR std::size_t ADP_only_alignment = 0u;

template < class T
, std::size_t NodesPerBlock = ADP_nodes_per_block
Expand All @@ -295,7 +295,7 @@ template < class T
, unsigned int AllocationDisableMask = 0>
class allocator;

static const std::size_t NodeAlloc_nodes_per_block = 256u;
BOOST_STATIC_CONSTEXPR std::size_t NodeAlloc_nodes_per_block = 256u;

template
< class T
Expand Down
10 changes: 5 additions & 5 deletions include/boost/container/deque.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ template <class T>
struct deque_value_traits
{
typedef T value_type;
static const bool trivial_dctr = dtl::is_trivially_destructible<value_type>::value;
static const bool trivial_dctr_after_move = ::boost::has_trivial_destructor_after_move<value_type>::value;
BOOST_STATIC_CONSTEXPR bool trivial_dctr = dtl::is_trivially_destructible<value_type>::value;
BOOST_STATIC_CONSTEXPR bool trivial_dctr_after_move = ::boost::has_trivial_destructor_after_move<value_type>::value;
};

template<class T, std::size_t BlockBytes, std::size_t BlockSize>
struct deque_block_size
{
BOOST_CONTAINER_STATIC_ASSERT_MSG(!(BlockBytes && BlockSize), "BlockBytes and BlockSize can't be specified at the same time");
static const std::size_t block_bytes = BlockBytes ? BlockBytes : 512u;
static const std::size_t value = BlockSize ? BlockSize : (sizeof(T) < block_bytes ? (block_bytes/sizeof(T)) : std::size_t(1));
BOOST_STATIC_CONSTEXPR std::size_t block_bytes = BlockBytes ? BlockBytes : 512u;
BOOST_STATIC_CONSTEXPR std::size_t value = BlockSize ? BlockSize : (sizeof(T) < block_bytes ? (block_bytes/sizeof(T)) : std::size_t(1));
};

namespace dtl {
Expand Down Expand Up @@ -2870,7 +2870,7 @@ struct has_trivial_destructor_after_move<boost::container::deque<T, Allocator, O
{
typedef typename boost::container::deque<T, Allocator, Options>::allocator_type allocator_type;
typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
static const bool value = ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
BOOST_STATIC_CONSTEXPR bool value = ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
::boost::has_trivial_destructor_after_move<pointer>::value;
};

Expand Down
2 changes: 1 addition & 1 deletion include/boost/container/detail/adaptive_node_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class private_adaptive_node_pool
private_adaptive_node_pool &operator=(const private_adaptive_node_pool &);

public:
static const std::size_t nodes_per_block = NodesPerBlock;
BOOST_STATIC_CONSTEXPR std::size_t nodes_per_block = NodesPerBlock;

//!Constructor. Never throws
private_adaptive_node_pool()
Expand Down
86 changes: 43 additions & 43 deletions include/boost/container/detail/adaptive_node_pool_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ template<class MultiallocationChain, class VoidPointer, class SizeType, unsigned
struct adaptive_pool_types
{
typedef VoidPointer void_pointer;
static const unsigned ordered = (Flags & (adaptive_pool_flag::size_ordered | adaptive_pool_flag::address_ordered));
BOOST_STATIC_CONSTEXPR unsigned ordered = (Flags & (adaptive_pool_flag::size_ordered | adaptive_pool_flag::address_ordered));
typedef block_container_traits<VoidPointer, SizeType, ordered> block_container_traits_t;
typedef typename block_container_traits_t::hook_t hook_t;
typedef hdr_offset_holder_t<SizeType> hdr_offset_holder;
static const unsigned int order_flags = Flags & (adaptive_pool_flag::size_ordered | adaptive_pool_flag::address_ordered);
BOOST_STATIC_CONSTEXPR unsigned int order_flags = Flags & (adaptive_pool_flag::size_ordered | adaptive_pool_flag::address_ordered);
typedef MultiallocationChain free_nodes_t;

struct block_info_t
Expand Down Expand Up @@ -253,11 +253,11 @@ template< std::size_t alignment
, std::size_t overhead_percent>
struct candidate_power_of_2_ct_helper
{
static const std::size_t hdr_subblock_elements_alone = (alignment - hdr_size - payload_per_allocation)/real_node_size;
static const std::size_t hdr_subblock_elements_first = (alignment - hdr_size - payload_per_allocation)/real_node_size;
static const std::size_t elements_per_b_subblock_mid = (alignment - hdr_offset_size)/real_node_size;
static const std::size_t elements_per_b_subblock_end = (alignment - hdr_offset_size - payload_per_allocation)/real_node_size;
static const std::size_t num_b_subblock =
BOOST_STATIC_CONSTEXPR std::size_t hdr_subblock_elements_alone = (alignment - hdr_size - payload_per_allocation)/real_node_size;
BOOST_STATIC_CONSTEXPR std::size_t hdr_subblock_elements_first = (alignment - hdr_size - payload_per_allocation)/real_node_size;
BOOST_STATIC_CONSTEXPR std::size_t elements_per_b_subblock_mid = (alignment - hdr_offset_size)/real_node_size;
BOOST_STATIC_CONSTEXPR std::size_t elements_per_b_subblock_end = (alignment - hdr_offset_size - payload_per_allocation)/real_node_size;
BOOST_STATIC_CONSTEXPR std::size_t num_b_subblock =
hdr_subblock_elements_alone >= min_elements_per_block
? 0
: ( ((hdr_subblock_elements_first + elements_per_b_subblock_end) >= min_elements_per_block)
Expand All @@ -266,18 +266,18 @@ struct candidate_power_of_2_ct_helper
)
;

static const std::size_t num_b_subblock_mid = (num_b_subblock > 1) ? (num_b_subblock - 1) : 0;
BOOST_STATIC_CONSTEXPR std::size_t num_b_subblock_mid = (num_b_subblock > 1) ? (num_b_subblock - 1) : 0;

static const std::size_t total_nodes = (num_b_subblock == 0)
BOOST_STATIC_CONSTEXPR std::size_t total_nodes = (num_b_subblock == 0)
? hdr_subblock_elements_alone
: ( (num_b_subblock == 1)
? (hdr_subblock_elements_first + elements_per_b_subblock_end)
: (hdr_subblock_elements_first + num_b_subblock_mid*elements_per_b_subblock_mid + elements_per_b_subblock_end)
)
;
static const std::size_t total_data = total_nodes*real_node_size;
static const std::size_t total_size = alignment*(num_b_subblock+1);
static const bool overhead_satisfied = (total_size - total_data)*100/total_size < overhead_percent;
BOOST_STATIC_CONSTEXPR std::size_t total_data = total_nodes*real_node_size;
BOOST_STATIC_CONSTEXPR std::size_t total_size = alignment*(num_b_subblock+1);
BOOST_STATIC_CONSTEXPR bool overhead_satisfied = (total_size - total_data)*100/total_size < overhead_percent;
};

template< std::size_t initial_alignment
Expand All @@ -299,7 +299,7 @@ struct candidate_power_of_2_ct
, hdr_offset_size
, overhead_percent> helper_t;

static const std::size_t candidate_power_of_2 = initial_alignment << std::size_t(!helper_t::overhead_satisfied);
BOOST_STATIC_CONSTEXPR std::size_t candidate_power_of_2 = initial_alignment << std::size_t(!helper_t::overhead_satisfied);

typedef typename candidate_power_of_2_ct
< candidate_power_of_2
Expand All @@ -312,9 +312,9 @@ struct candidate_power_of_2_ct
, !helper_t::overhead_satisfied
>::type type;

static const std::size_t alignment = type::alignment;
static const std::size_t num_subblocks = type::num_subblocks;
static const std::size_t real_num_node = type::real_num_node;
BOOST_STATIC_CONSTEXPR std::size_t alignment = type::alignment;
BOOST_STATIC_CONSTEXPR std::size_t num_subblocks = type::num_subblocks;
BOOST_STATIC_CONSTEXPR std::size_t real_num_node = type::real_num_node;
};

template< std::size_t initial_alignment
Expand Down Expand Up @@ -354,9 +354,9 @@ struct candidate_power_of_2_ct
, hdr_offset_size
, overhead_percent> helper_t;

static const std::size_t alignment = initial_alignment;
static const std::size_t num_subblocks = helper_t::num_b_subblock+1;
static const std::size_t real_num_node = helper_t::total_nodes;
BOOST_STATIC_CONSTEXPR std::size_t alignment = initial_alignment;
BOOST_STATIC_CONSTEXPR std::size_t num_subblocks = helper_t::num_b_subblock+1;
BOOST_STATIC_CONSTEXPR std::size_t real_num_node = helper_t::total_nodes;
};

/////////////////////////////////////////////
Expand Down Expand Up @@ -429,13 +429,13 @@ class private_adaptive_node_pool_impl_common
typedef typename SegmentManagerBase::size_type size_type;
//Flags
//align_only
static const bool AlignOnly = (Flags & adaptive_pool_flag::align_only) != 0;
BOOST_STATIC_CONSTEXPR bool AlignOnly = (Flags & adaptive_pool_flag::align_only) != 0;
typedef bool_<AlignOnly> IsAlignOnly;
typedef true_ AlignOnlyTrue;
typedef false_ AlignOnlyFalse;

typedef typename SegmentManagerBase::void_pointer void_pointer;
static const typename SegmentManagerBase::
BOOST_STATIC_CONSTEXPR typename SegmentManagerBase::
size_type PayloadPerAllocation = SegmentManagerBase::PayloadPerAllocation;

typedef typename boost::intrusive::pointer_traits
Expand All @@ -453,9 +453,9 @@ class private_adaptive_node_pool_impl_common
typedef typename adaptive_pool_types_t::hdr_offset_holder hdr_offset_holder;
typedef private_adaptive_node_pool_impl_common this_type;

static const size_type MaxAlign = alignment_of<void_pointer>::value;
static const size_type HdrSize = ((sizeof(block_info_t)-1)/MaxAlign+1)*MaxAlign;
static const size_type HdrOffsetSize = ((sizeof(hdr_offset_holder)-1)/MaxAlign+1)*MaxAlign;
BOOST_STATIC_CONSTEXPR size_type MaxAlign = alignment_of<void_pointer>::value;
BOOST_STATIC_CONSTEXPR size_type HdrSize = ((sizeof(block_info_t)-1)/MaxAlign+1)*MaxAlign;
BOOST_STATIC_CONSTEXPR size_type HdrOffsetSize = ((sizeof(hdr_offset_holder)-1)/MaxAlign+1)*MaxAlign;

segment_mngr_base_ptr_t mp_segment_mngr_base; //Segment manager
block_container_t m_block_container; //Intrusive block list
Expand Down Expand Up @@ -981,9 +981,9 @@ template< class SizeType
, bool AlignOnly>
struct calculate_alignment_ct
{
static const std::size_t alignment = upper_power_of_2_ct<SizeType, HdrSize + RealNodeSize*NodesPerBlock>::value;
static const std::size_t num_subblocks = 0;
static const std::size_t real_num_node = (alignment - PayloadPerAllocation - HdrSize)/RealNodeSize;
BOOST_STATIC_CONSTEXPR std::size_t alignment = upper_power_of_2_ct<SizeType, HdrSize + RealNodeSize*NodesPerBlock>::value;
BOOST_STATIC_CONSTEXPR std::size_t num_subblocks = 0;
BOOST_STATIC_CONSTEXPR std::size_t real_num_node = (alignment - PayloadPerAllocation - HdrSize)/RealNodeSize;
};

template< class SizeType
Expand Down Expand Up @@ -1013,9 +1013,9 @@ struct calculate_alignment_ct
, OverheadPercent
>::type type;

static const std::size_t alignment = type::alignment;
static const std::size_t num_subblocks = type::num_subblocks;
static const std::size_t real_num_node = type::real_num_node;
BOOST_STATIC_CONSTEXPR std::size_t alignment = type::alignment;
BOOST_STATIC_CONSTEXPR std::size_t num_subblocks = type::num_subblocks;
BOOST_STATIC_CONSTEXPR std::size_t real_num_node = type::real_num_node;
};


Expand Down Expand Up @@ -1046,17 +1046,17 @@ class private_adaptive_node_pool_impl_ct
typedef typename base_t::multiallocation_chain multiallocation_chain;
typedef typename base_t::segment_manager_base_type segment_manager_base_type;

static const typename base_t::size_type PayloadPerAllocation = base_t::PayloadPerAllocation;
BOOST_STATIC_CONSTEXPR typename base_t::size_type PayloadPerAllocation = base_t::PayloadPerAllocation;

//align_only
static const bool AlignOnly = base_t::AlignOnly;
BOOST_STATIC_CONSTEXPR bool AlignOnly = base_t::AlignOnly;

private:
static const size_type MaxAlign = base_t::MaxAlign;
static const size_type HdrSize = base_t::HdrSize;
static const size_type HdrOffsetSize = base_t::HdrOffsetSize;
BOOST_STATIC_CONSTEXPR size_type MaxAlign = base_t::MaxAlign;
BOOST_STATIC_CONSTEXPR size_type HdrSize = base_t::HdrSize;
BOOST_STATIC_CONSTEXPR size_type HdrOffsetSize = base_t::HdrOffsetSize;

static const size_type RealNodeSize = lcm_ct<NodeSize, alignment_of<void_pointer>::value>::value;
BOOST_STATIC_CONSTEXPR size_type RealNodeSize = lcm_ct<NodeSize, alignment_of<void_pointer>::value>::value;

typedef calculate_alignment_ct
< size_type, HdrSize, PayloadPerAllocation
Expand All @@ -1065,9 +1065,9 @@ class private_adaptive_node_pool_impl_ct
//Round the size to a power of two value.
//This is the total memory size (including payload) that we want to
//allocate from the general-purpose allocator
static const size_type NumSubBlocks = data_t::num_subblocks;
static const size_type RealNumNode = data_t::real_num_node;
static const size_type RealBlockAlignment = data_t::alignment;
BOOST_STATIC_CONSTEXPR size_type NumSubBlocks = data_t::num_subblocks;
BOOST_STATIC_CONSTEXPR size_type RealNumNode = data_t::real_num_node;
BOOST_STATIC_CONSTEXPR size_type RealBlockAlignment = data_t::alignment;

public:

Expand Down Expand Up @@ -1165,14 +1165,14 @@ class private_adaptive_node_pool_impl_rt
typedef typename impl_t::size_type size_type;
typedef typename impl_t::multiallocation_chain multiallocation_chain;

static const typename impl_t::size_type PayloadPerAllocation = impl_t::PayloadPerAllocation;
BOOST_STATIC_CONSTEXPR typename impl_t::size_type PayloadPerAllocation = impl_t::PayloadPerAllocation;

//Flags
//align_only
static const bool AlignOnly = impl_t::AlignOnly;
BOOST_STATIC_CONSTEXPR bool AlignOnly = impl_t::AlignOnly;

static const size_type HdrSize = impl_t::HdrSize;
static const size_type HdrOffsetSize = impl_t::HdrOffsetSize;
BOOST_STATIC_CONSTEXPR size_type HdrSize = impl_t::HdrSize;
BOOST_STATIC_CONSTEXPR size_type HdrOffsetSize = impl_t::HdrOffsetSize;

public:

Expand Down
Loading

0 comments on commit 0977e6b

Please sign in to comment.