Skip to content

Commit c3187f0

Browse files
committed
Assert that both the underlying container and dynamic_bitset provide at least bidirectional iterators
The assert uses C++20 concepts, so it is only performed in C++20 or later. Note that, while evaluating the concept for the second assert, MSVC 2022 complained a constructor of class reference was private, therefore we added a friend declaration.
1 parent 7bfba71 commit c3187f0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/boost/dynamic_bitset/dynamic_bitset.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "boost/dynamic_bitset_fwd.hpp"
2525
#include "boost/limits.hpp"
2626
#include <iosfwd>
27+
#include <iterator>
2728
#include <string>
2829
#include <type_traits>
2930
#include <vector>
@@ -197,6 +198,7 @@ class dynamic_bitset
197198
class reference
198199
{
199200
friend class dynamic_bitset< Block, AllocatorOrContainer >;
201+
friend class bit_iterator< dynamic_bitset >;
200202

201203
//! The one and only non-copy ctor
202204
// -------------------------------------------------------------------
@@ -294,6 +296,11 @@ class dynamic_bitset
294296
// -----------------------------------------------------------------------
295297
typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
296298

299+
#if __cplusplus >= 202002L
300+
static_assert( std::bidirectional_iterator< typename buffer_type::iterator >, "AllocatorOrContainer doesn't offer at least BidirectionalIterators" );
301+
static_assert( std::bidirectional_iterator< iterator > );
302+
#endif
303+
297304
//! Constructs a bitset of size zero.
298305
//!
299306
//! \par Postconditions

include/boost/dynamic_bitset/impl/dynamic_bitset.ipp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <algorithm>
2626
#include <climits>
2727
#include <istream>
28-
#include <iterator>
2928
#include <ostream>
3029
#include <stdexcept>
3130
#include <utility>

0 commit comments

Comments
 (0)