Skip to content

Commit

Permalink
Use BOOST_INTRUSIVE_STATIC_ASSERT instead of BOOST_STATIC_ASSERT to r…
Browse files Browse the repository at this point in the history
…educe library level and weight.
  • Loading branch information
igaztanaga committed Jan 2, 2024
1 parent 60def75 commit e84e9b7
Show file tree
Hide file tree
Showing 48 changed files with 240 additions and 246 deletions.
5 changes: 0 additions & 5 deletions example/doc_map.cpp
Expand Up @@ -10,8 +10,6 @@
//
/////////////////////////////////////////////////////////////////////////////
//[doc_map_code
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/unordered_set.hpp>
#include <vector>
Expand Down Expand Up @@ -50,9 +48,6 @@ typedef unordered_set< MyClass, key_of_value<first_int_is_key> > UnorderedMap;

int main()
{
BOOST_STATIC_ASSERT((boost::is_same< OrderedMap::key_type, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<UnorderedMap::key_type, int>::value));

//Create several MyClass objects, each one with a different value
//and insert them into the omap
std::vector<MyClass> values;
Expand Down
5 changes: 2 additions & 3 deletions include/boost/intrusive/avl_set.hpp
Expand Up @@ -17,7 +17,6 @@
#include <boost/intrusive/avltree.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/move/utility_core.hpp>
#include <boost/static_assert.hpp>

#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
Expand Down Expand Up @@ -523,7 +522,7 @@ class avl_set
typedef typename Base::const_iterator const_iterator;

//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));

inline avl_set()
: Base()
Expand Down Expand Up @@ -1018,7 +1017,7 @@ class avl_multiset
typedef typename Base::const_iterator const_iterator;

//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));

inline avl_multiset()
: Base()
Expand Down
3 changes: 1 addition & 2 deletions include/boost/intrusive/avltree.hpp
Expand Up @@ -18,7 +18,6 @@
#include <boost/intrusive/detail/minimal_less_equal_header.hpp>
#include <boost/intrusive/detail/minimal_pair_header.hpp>

#include <boost/static_assert.hpp>
#include <boost/intrusive/avl_set_hook.hpp>
#include <boost/intrusive/detail/avltree_node.hpp>
#include <boost/intrusive/bstree.hpp>
Expand Down Expand Up @@ -533,7 +532,7 @@ class avltree
typedef typename Base::const_reverse_iterator const_reverse_iterator;

//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));

inline avltree()
: Base()
Expand Down
5 changes: 2 additions & 3 deletions include/boost/intrusive/bs_set.hpp
Expand Up @@ -17,7 +17,6 @@
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/bstree.hpp>
#include <boost/move/utility_core.hpp>
#include <boost/static_assert.hpp>

#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
Expand Down Expand Up @@ -520,7 +519,7 @@ class bs_set
typedef typename Base::const_iterator const_iterator;

//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));

inline bs_set()
: Base()
Expand Down Expand Up @@ -1014,7 +1013,7 @@ class bs_multiset
typedef typename Base::const_iterator const_iterator;

//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));

inline bs_multiset()
: Base()
Expand Down
13 changes: 6 additions & 7 deletions include/boost/intrusive/bstree.hpp
Expand Up @@ -16,7 +16,6 @@
#include <boost/intrusive/intrusive_fwd.hpp>

#include <boost/intrusive/detail/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/bs_set_hook.hpp>
#include <boost/intrusive/detail/tree_node.hpp>
Expand Down Expand Up @@ -113,7 +112,7 @@ struct bstbase3

static bstbase3 &get_tree_base_from_end_iterator(const const_iterator &end_iterator)
{
BOOST_STATIC_ASSERT(has_container_from_iterator);
BOOST_INTRUSIVE_STATIC_ASSERT(has_container_from_iterator);
node_ptr p = end_iterator.pointed_node();
header_holder_type* h = header_holder_type::get_holder(p);
holder_t *holder = get_parent_from_member<holder_t, header_holder_type>(h, &holder_t::root);
Expand Down Expand Up @@ -207,13 +206,13 @@ struct bstbase3

static iterator s_iterator_to(reference value) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((!stateful_value_traits));
BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
return iterator (value_traits::to_node_ptr(value), const_value_traits_ptr());
}

static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((!stateful_value_traits));
BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
return const_iterator (value_traits::to_node_ptr(*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value))), const_value_traits_ptr());
}

Expand Down Expand Up @@ -666,7 +665,7 @@ class bstree_impl
static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;

//Constant-time size is incompatible with auto-unlink hooks!
BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
BOOST_INTRUSIVE_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));


protected:
Expand Down Expand Up @@ -1961,7 +1960,7 @@ class bstree_impl
//! functor a compilation error will be issued.
static void remove_node(reference value) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((!constant_time_size));
BOOST_INTRUSIVE_STATIC_ASSERT((!constant_time_size));
node_ptr to_remove(value_traits::to_node_ptr(value));
node_algorithms::unlink(to_remove);
BOOST_IF_CONSTEXPR(safemode_or_autounlink)
Expand Down Expand Up @@ -2184,7 +2183,7 @@ class bstree
typedef typename Base::const_iterator const_iterator;

//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));

inline bstree()
: Base()
Expand Down
5 changes: 2 additions & 3 deletions include/boost/intrusive/detail/generic_hook.hpp
Expand Up @@ -27,7 +27,6 @@
#include <boost/intrusive/detail/assert.hpp>
#include <boost/intrusive/detail/node_holder.hpp>
#include <boost/intrusive/detail/algo_type.hpp>
#include <boost/static_assert.hpp>

namespace boost {
namespace intrusive {
Expand Down Expand Up @@ -202,13 +201,13 @@ class generic_hook
inline bool is_linked() const BOOST_NOEXCEPT
{
//is_linked() can be only used in safe-mode or auto-unlink
BOOST_STATIC_ASSERT(( hooktags::safemode_or_autounlink ));
BOOST_INTRUSIVE_STATIC_ASSERT(( hooktags::safemode_or_autounlink ));
return !node_algorithms::unique(this->this_ptr());
}

inline void unlink() BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT(( (int)hooktags::link_mode == (int)auto_unlink ));
BOOST_INTRUSIVE_STATIC_ASSERT(( (int)hooktags::link_mode == (int)auto_unlink ));
node_ptr n(this->this_ptr());
if(!node_algorithms::inited(n)){
node_algorithms::unlink(n);
Expand Down
5 changes: 2 additions & 3 deletions include/boost/intrusive/detail/parent_from_member.hpp
Expand Up @@ -26,8 +26,7 @@

#if defined(_MSC_VER)
#define BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER
#include <boost/static_assert.hpp>
#endif
#endif

namespace boost {
namespace intrusive {
Expand All @@ -49,7 +48,7 @@ BOOST_INTRUSIVE_FORCEINLINE std::ptrdiff_t offset_from_pointer_to_member(const M
//MSVC ABI can use up to 3 int32 to represent pointer to member data
//with virtual base classes, in those cases there is no simple to
//obtain the address of the parent. So static assert to avoid runtime errors
BOOST_STATIC_ASSERT( sizeof(caster) == sizeof(int) );
BOOST_INTRUSIVE_STATIC_ASSERT( sizeof(caster) == sizeof(int) );

caster.ptr_to_member = ptr_to_member;
return std::ptrdiff_t(caster.offset);
Expand Down
3 changes: 1 addition & 2 deletions include/boost/intrusive/detail/slist_iterator.hpp
Expand Up @@ -27,7 +27,6 @@
#include <boost/intrusive/detail/std_fwd.hpp>
#include <boost/intrusive/detail/iiterator.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/static_assert.hpp>

namespace boost {
namespace intrusive {
Expand Down Expand Up @@ -72,7 +71,7 @@ class slist_iterator

inline explicit slist_iterator(node_ptr nodeptr)
: members_(nodeptr, const_value_traits_ptr())
{ BOOST_STATIC_ASSERT((stateful_value_traits == false)); }
{ BOOST_INTRUSIVE_STATIC_ASSERT((stateful_value_traits == false)); }

inline slist_iterator(const slist_iterator &other)
: members_(other.pointed_node(), other.get_value_traits())
Expand Down
28 changes: 28 additions & 0 deletions include/boost/intrusive/detail/workaround.hpp
Expand Up @@ -84,4 +84,32 @@
# define BOOST_INTRUSIVE_CATCH_END }
#endif

#ifndef BOOST_NO_CXX11_STATIC_ASSERT
# ifndef BOOST_NO_CXX11_VARIADIC_MACROS
# define BOOST_INTRUSIVE_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
# else
# define BOOST_INTRUSIVE_STATIC_ASSERT( B ) static_assert(B, #B)
# endif
#else
namespace boost {
namespace intrusive {
namespace detail {

template<bool B>
struct STATIC_ASSERTION_FAILURE;

template<>
struct STATIC_ASSERTION_FAILURE<true>{};

template<unsigned> struct static_assert_test {};

}}}

#define BOOST_INTRUSIVE_STATIC_ASSERT(B) \
typedef ::boost::intrusive::detail::static_assert_test<\
(unsigned)sizeof(::boost::intrusive::detail::STATIC_ASSERTION_FAILURE<bool(B)>)>\
BOOST_JOIN(boost_static_assert_typedef_, __LINE__) BOOST_ATTRIBUTE_UNUSED

#endif

#endif //#ifndef BOOST_INTRUSIVE_DETAIL_WORKAROUND_HPP
19 changes: 9 additions & 10 deletions include/boost/intrusive/hashtable.hpp
Expand Up @@ -60,7 +60,6 @@

//boost
#include <boost/intrusive/detail/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/move/utility_core.hpp>
#include <boost/move/adl_move_swap.hpp>
#include <boost/move/algo/detail/search.hpp>
Expand Down Expand Up @@ -2059,14 +2058,14 @@ struct hashdata_internal

static local_iterator s_local_iterator_to(reference value) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((!stateful_value_traits));
BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
siterator sit(value_traits::to_node_ptr(value));
return local_iterator(sit, const_value_traits_ptr());
}

static const_local_iterator s_local_iterator_to(const_reference value) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((!stateful_value_traits));
BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
siterator const sit = siterator
( pointer_traits<node_ptr>::const_cast_from
(value_traits::to_node_ptr(value))
Expand Down Expand Up @@ -2329,11 +2328,11 @@ class hashtable_impl

//Configuration error: compare_hash<> can't be specified without store_hash<>
//See documentation for more explanations
BOOST_STATIC_ASSERT((!compare_hash || store_hash));
BOOST_INTRUSIVE_STATIC_ASSERT((!compare_hash || store_hash));

//Configuration error: fasmod_buckets<> can't be specified with incremental<> or power_2_buckets<>
//See documentation for more explanations
BOOST_STATIC_ASSERT(!(fastmod_buckets && power_2_buckets));
BOOST_INTRUSIVE_STATIC_ASSERT(!(fastmod_buckets && power_2_buckets));

typedef typename internal_type::slist_node_ptr slist_node_ptr;
typedef typename pointer_traits
Expand All @@ -2360,9 +2359,9 @@ class hashtable_impl
static const bool safemode_or_autounlink = internal_type::safemode_or_autounlink;

//Constant-time size is incompatible with auto-unlink hooks!
BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
BOOST_INTRUSIVE_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
//Cache begin is incompatible with auto-unlink hooks!
BOOST_STATIC_ASSERT(!(cache_begin && ((int)value_traits::link_mode == (int)auto_unlink)));
BOOST_INTRUSIVE_STATIC_ASSERT(!(cache_begin && ((int)value_traits::link_mode == (int)auto_unlink)));


/// @endcond
Expand Down Expand Up @@ -3571,7 +3570,7 @@ class hashtable_impl
bool incremental_rehash(bool grow = true)
{
//This function is only available for containers with incremental hashing
BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
BOOST_INTRUSIVE_STATIC_ASSERT(( incremental && power_2_buckets ));
const std::size_t split_idx = this->split_count();
const std::size_t bucket_cnt = this->bucket_count();
bool ret = false;
Expand Down Expand Up @@ -3636,7 +3635,7 @@ class hashtable_impl
bool incremental_rehash(const bucket_traits &new_bucket_traits) BOOST_NOEXCEPT
{
//This function is only available for containers with incremental hashing
BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
BOOST_INTRUSIVE_STATIC_ASSERT(( incremental && power_2_buckets ));
const bucket_ptr new_buckets = new_bucket_traits.bucket_begin();
const size_type new_bucket_count_stdszt = static_cast<SizeType>(new_bucket_traits.bucket_count() - bucket_overhead);
BOOST_INTRUSIVE_INVARIANT_ASSERT(sizeof(size_type) >= sizeof(std::size_t) || new_bucket_count_stdszt <= size_type(-1));
Expand Down Expand Up @@ -4334,7 +4333,7 @@ class hashtable
typedef typename Base::key_equal key_equal;

//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));

inline explicit hashtable ( const bucket_traits &b_traits
, const hasher & hash_func = hasher()
Expand Down
11 changes: 5 additions & 6 deletions include/boost/intrusive/list.hpp
Expand Up @@ -37,7 +37,6 @@
#include <boost/intrusive/detail/algorithm.hpp>

#include <boost/move/utility_core.hpp>
#include <boost/static_assert.hpp>

#include <boost/intrusive/detail/value_functors.hpp>
#include <cstddef> //std::size_t, etc.
Expand Down Expand Up @@ -123,7 +122,7 @@ class list_impl
static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;

//Constant-time size is incompatible with auto-unlink hooks!
BOOST_STATIC_ASSERT(!(constant_time_size &&
BOOST_INTRUSIVE_STATIC_ASSERT(!(constant_time_size &&
((int)value_traits::link_mode == (int)auto_unlink)
));

Expand Down Expand Up @@ -1272,7 +1271,7 @@ class list_impl
//! is stateless.
static iterator s_iterator_to(reference value) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((!stateful_value_traits));
BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value)));
return iterator(value_traits::to_node_ptr(value), const_value_traits_ptr());
}
Expand All @@ -1290,7 +1289,7 @@ class list_impl
//! is stateless.
static const_iterator s_iterator_to(const_reference value) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((!stateful_value_traits));
BOOST_INTRUSIVE_STATIC_ASSERT((!stateful_value_traits));
reference r =*detail::uncast(pointer_traits<const_pointer>::pointer_to(value));
BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(r)));
return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr());
Expand Down Expand Up @@ -1394,7 +1393,7 @@ class list_impl
private:
static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT((has_container_from_iterator));
BOOST_INTRUSIVE_STATIC_ASSERT((has_container_from_iterator));
node_ptr p = end_iterator.pointed_node();
header_holder_type* h = header_holder_type::get_holder(p);
root_plus_size* r = detail::parent_from_member
Expand Down Expand Up @@ -1466,7 +1465,7 @@ class list
#endif
>::type Base;
//Assert if passed value traits are compatible with the type
BOOST_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
BOOST_MOVABLE_BUT_NOT_COPYABLE(list)

public:
Expand Down
6 changes: 3 additions & 3 deletions include/boost/intrusive/pack_options.hpp
Expand Up @@ -14,7 +14,7 @@
#define BOOST_INTRUSIVE_PACK_OPTIONS_HPP

#include <boost/intrusive/detail/config_begin.hpp>

#include <boost/intrusive/detail/workaround.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
Expand Down Expand Up @@ -338,7 +338,7 @@ struct pack_options
//!
//! typedef pack_options< empty_default, typename my_pointer<void*> >::type::my_pointer_type type;
//!
//! BOOST_STATIC_ASSERT(( boost::is_same<type, void>::value ));
//! BOOST_INTRUSIVE_STATIC_ASSERT(( boost::is_same<type, void>::value ));
//!
//! \endcode
#define BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME)
Expand Down Expand Up @@ -368,7 +368,7 @@ struct pack_options
//!
//! const bool is_incremental = pack_options< empty_default, incremental<true> >::type::is_incremental;
//!
//! BOOST_STATIC_ASSERT(( is_incremental == true ));
//! BOOST_INTRUSIVE_STATIC_ASSERT(( is_incremental == true ));
//!
//! \endcode
#define BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME)
Expand Down

0 comments on commit e84e9b7

Please sign in to comment.