Skip to content

Commit 1b4af0d

Browse files
committed
Add more BOOST_IF_CONSTEXPR for constant-conditions
1 parent 6ef2c48 commit 1b4af0d

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

include/boost/intrusive/bstree.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ class bstree_impl
955955
//! <b>Throws</b>: Nothing.
956956
bool empty() const BOOST_NOEXCEPT
957957
{
958-
if(ConstantTimeSize){
958+
BOOST_IF_CONSTEXPR(constant_time_size){
959959
return !this->data_type::sz_traits().get_size();
960960
}
961961
else{
@@ -2081,7 +2081,8 @@ class bstree_impl
20812081

20822082
friend bool operator==(const bstree_impl &x, const bstree_impl &y)
20832083
{
2084-
if(constant_time_size && x.size() != y.size()){
2084+
BOOST_IF_CONSTEXPR(constant_time_size)
2085+
if(x.size() != y.size()){
20852086
return false;
20862087
}
20872088
return boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());

include/boost/intrusive/hashtable.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,7 +3074,7 @@ class hashtable_impl
30743074

30753075
std::size_t cnt(0);
30763076
if(success){
3077-
if(optimize_multikey){
3077+
BOOST_IF_CONSTEXPR(optimize_multikey){
30783078
siterator past_last_in_group = it;
30793079
(priv_go_to_last_in_group)(past_last_in_group, optimize_multikey_t());
30803080
++past_last_in_group;
@@ -3749,7 +3749,8 @@ class hashtable_impl
37493749
friend bool operator==(const hashtable_impl &x, const hashtable_impl &y)
37503750
{
37513751
//Taken from N3068
3752-
if(constant_time_size && x.size() != y.size()){
3752+
BOOST_IF_CONSTEXPR(constant_time_size)
3753+
if(x.size() != y.size()){
37533754
return false;
37543755
}
37553756

include/boost/intrusive/list.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,8 @@ class list_impl
13931393

13941394
friend bool operator==(const list_impl &x, const list_impl &y)
13951395
{
1396-
if(constant_time_size && x.size() != y.size()){
1396+
BOOST_IF_CONSTEXPR(constant_time_size)
1397+
if(x.size() != y.size()){
13971398
return false;
13981399
}
13991400
return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());

include/boost/intrusive/slist.hpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,9 @@ class slist_impl
828828
BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || node_algorithms::inited(n));
829829
node_ptr prev_n(prev_p.pointed_node());
830830
node_algorithms::link_after(prev_n, n);
831-
if(cache_last && (this->get_last_node() == prev_n)){
831+
832+
BOOST_IF_CONSTEXPR(cache_last)
833+
if(this->get_last_node() == prev_n){
832834
this->set_last_node(n);
833835
}
834836
this->priv_size_traits().increment();
@@ -860,7 +862,8 @@ class slist_impl
860862
prev_n = n;
861863
}
862864
//Now fix special cases if needed
863-
if(cache_last && (this->get_last_node() == prev_p.pointed_node())){
865+
BOOST_IF_CONSTEXPR(cache_last)
866+
if(this->get_last_node() == prev_p.pointed_node()){
864867
this->set_last_node(prev_n);
865868
}
866869
BOOST_IF_CONSTEXPR(constant_time_size){
@@ -1056,7 +1059,9 @@ class slist_impl
10561059
++it;
10571060
node_ptr prev_n(prev.pointed_node());
10581061
node_algorithms::unlink_after(prev_n);
1059-
if(cache_last && (to_erase == this->get_last_node())){
1062+
1063+
BOOST_IF_CONSTEXPR(cache_last)
1064+
if(to_erase == this->get_last_node()){
10601065
this->set_last_node(prev_n);
10611066
}
10621067
BOOST_IF_CONSTEXPR(safemode_or_autounlink)
@@ -1143,7 +1148,9 @@ class slist_impl
11431148
disposer(priv_value_traits().to_value_ptr(to_erase));
11441149
this->priv_size_traits().decrement();
11451150
}
1146-
if(cache_last && (node_traits::get_next(bfp) == this->get_end_node())){
1151+
1152+
BOOST_IF_CONSTEXPR(cache_last)
1153+
if(node_traits::get_next(bfp) == this->get_end_node()){
11471154
this->set_last_node(bfp);
11481155
}
11491156
return l.unconst();
@@ -1584,7 +1591,8 @@ class slist_impl
15841591
//! <b>Note</b>: Iterators and references are not invalidated
15851592
void reverse() BOOST_NOEXCEPT
15861593
{
1587-
if(cache_last && !this->empty()){
1594+
BOOST_IF_CONSTEXPR(cache_last)
1595+
if(!this->empty()){
15881596
this->set_last_node(node_traits::get_next(this->get_root_node()));
15891597
}
15901598
this->priv_reverse(detail::bool_<linear>());
@@ -1984,7 +1992,8 @@ class slist_impl
19841992

19851993
friend bool operator==(const slist_impl &x, const slist_impl &y)
19861994
{
1987-
if(constant_time_size && x.size() != y.size()){
1995+
BOOST_IF_CONSTEXPR(constant_time_size)
1996+
if(x.size() != y.size()){
19881997
return false;
19891998
}
19901999
return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());
@@ -2011,7 +2020,8 @@ class slist_impl
20112020
private:
20122021
void priv_splice_after(node_ptr prev_pos_n, slist_impl &x, node_ptr before_f_n, node_ptr before_l_n)
20132022
{
2014-
if (cache_last && (before_f_n != before_l_n)){
2023+
BOOST_IF_CONSTEXPR(cache_last)
2024+
if(before_f_n != before_l_n){
20152025
if(prev_pos_n == this->get_last_node()){
20162026
this->set_last_node(before_l_n);
20172027
}
@@ -2045,7 +2055,10 @@ class slist_impl
20452055
void priv_shift_backwards(size_type n, detail::bool_<false>)
20462056
{
20472057
node_ptr l = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n);
2048-
if(cache_last && l){
2058+
(void)l;
2059+
2060+
BOOST_IF_CONSTEXPR(cache_last)
2061+
if(l){
20492062
this->set_last_node(l);
20502063
}
20512064
}
@@ -2066,7 +2079,10 @@ class slist_impl
20662079
void priv_shift_forward(size_type n, detail::bool_<false>)
20672080
{
20682081
node_ptr l = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n);
2069-
if(cache_last && l){
2082+
(void)l;
2083+
2084+
BOOST_IF_CONSTEXPR(cache_last)
2085+
if(l){
20702086
this->set_last_node(l);
20712087
}
20722088
}

include/boost/intrusive/unordered_set.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,11 @@ class unordered_set_impl
386386

387387
friend bool operator==(const unordered_set_impl &x, const unordered_set_impl &y)
388388
{
389-
if(table_type::constant_time_size && x.size() != y.size()){
389+
BOOST_IF_CONSTEXPR(table_type::constant_time_size)
390+
if(x.size() != y.size()){
390391
return false;
391392
}
393+
392394
//Find each element of x in y
393395
for (const_iterator ix = x.cbegin(), ex = x.cend(), ey = y.cend(); ix != ex; ++ix){
394396
const_iterator iy = y.find(key_of_value()(*ix));

0 commit comments

Comments
 (0)