mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
Add a constructor from basic_string_view in C++17 or later
Note that we have MrDocs compile as C++17 again (a change that we had reverted).
This commit is contained in:
@@ -82,6 +82,9 @@ if (DYNAMIC_BITSET_MRDOCS_BUILD)
|
|||||||
# Create a custom target for MrDocs.
|
# Create a custom target for MrDocs.
|
||||||
add_library(dynamic_bitset_mrdocs_target ${TEMP_CPP_FILE})
|
add_library(dynamic_bitset_mrdocs_target ${TEMP_CPP_FILE})
|
||||||
|
|
||||||
|
# This is to get the documentation of the constructor from basic_string_view.
|
||||||
|
set_target_properties(dynamic_bitset_mrdocs_target PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
|
||||||
|
|
||||||
# Set any other target properties here.
|
# Set any other target properties here.
|
||||||
target_include_directories(dynamic_bitset_mrdocs_target PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
target_include_directories(dynamic_bitset_mrdocs_target PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
target_link_libraries(dynamic_bitset_mrdocs_target PRIVATE boost_dynamic_bitset)
|
target_link_libraries(dynamic_bitset_mrdocs_target PRIVATE boost_dynamic_bitset)
|
||||||
|
|||||||
@@ -60,4 +60,8 @@ make_non_const( T t )
|
|||||||
# define BOOST_DYNAMIC_BITSET_SPECIALIZE_STD_HASH
|
# define BOOST_DYNAMIC_BITSET_SPECIALIZE_STD_HASH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ( defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
|
||||||
|
# define BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // include guard
|
#endif // include guard
|
||||||
|
|||||||
@@ -386,6 +386,27 @@ public:
|
|||||||
template< typename CharT >
|
template< typename CharT >
|
||||||
dynamic_bitset( const CharT * s, std::size_t n = std::size_t( -1 ), size_type num_bits = npos, const allocator_type & alloc = allocator_type() );
|
dynamic_bitset( const CharT * s, std::size_t n = std::size_t( -1 ), size_type num_bits = npos, const allocator_type & alloc = allocator_type() );
|
||||||
|
|
||||||
|
#if defined( BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER )
|
||||||
|
|
||||||
|
//! Similar to the constructor from a pointer to a C-style
|
||||||
|
//! string, but takes a `std::basic_string_view`. This
|
||||||
|
//! constructor is only available if DynamicBitset is compiled
|
||||||
|
//! as C++17 or later.
|
||||||
|
//!
|
||||||
|
//! \pre
|
||||||
|
//! The characters in `sv` are '0' or '1'.
|
||||||
|
//!
|
||||||
|
//! \param sv The basic_string_view to construct from.
|
||||||
|
//! \param num_bits The size of the bitset to construct, if
|
||||||
|
//! different from `npos`. (Otherwise the size of the bitset is
|
||||||
|
//! `sv.length()`.)
|
||||||
|
//! \param alloc The allocator to use.
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
template< typename CharT, typename Traits >
|
||||||
|
dynamic_bitset( std::basic_string_view< CharT, Traits > sv, size_type num_bits = npos, const allocator_type & alloc = allocator_type() );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//! Constructs a bitset from a range of blocks or from an
|
//! Constructs a bitset from a range of blocks or from an
|
||||||
//! integer.
|
//! integer.
|
||||||
//!
|
//!
|
||||||
@@ -1308,7 +1329,7 @@ private:
|
|||||||
void init_from_block_range( BlockIter first, BlockIter last );
|
void init_from_block_range( BlockIter first, BlockIter last );
|
||||||
|
|
||||||
template< typename CharT, typename Traits = std::char_traits< CharT > >
|
template< typename CharT, typename Traits = std::char_traits< CharT > >
|
||||||
void init_from_string( const CharT * s, std::size_t pos, std::size_t n, size_type num_bits );
|
void init_from_string( const CharT * s, std::size_t string_length, std::size_t pos, std::size_t n, size_type num_bits );
|
||||||
|
|
||||||
void init_from_unsigned_long( size_type num_bits, unsigned long value /*,
|
void init_from_unsigned_long( size_type num_bits, unsigned long value /*,
|
||||||
const allocator_type& alloc*/
|
const allocator_type& alloc*/
|
||||||
|
|||||||
@@ -494,7 +494,7 @@ dynamic_bitset< Block, AllocatorOrContainer >::dynamic_bitset(
|
|||||||
|
|
||||||
: m_bits( alloc ), m_num_bits( 0 )
|
: m_bits( alloc ), m_num_bits( 0 )
|
||||||
{
|
{
|
||||||
init_from_string( s.c_str(), pos, n, num_bits );
|
init_from_string( s.c_str(), s.length(), pos, n, num_bits );
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename Block, typename AllocatorOrContainer >
|
template< typename Block, typename AllocatorOrContainer >
|
||||||
@@ -506,9 +506,23 @@ dynamic_bitset< Block, AllocatorOrContainer >::dynamic_bitset(
|
|||||||
const allocator_type & alloc )
|
const allocator_type & alloc )
|
||||||
: m_bits( alloc ), m_num_bits( 0 )
|
: m_bits( alloc ), m_num_bits( 0 )
|
||||||
{
|
{
|
||||||
init_from_string( s, 0, n, num_bits );
|
init_from_string( s, std::char_traits< CharT >::length( s ), 0, n, num_bits );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined( BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER )
|
||||||
|
|
||||||
|
template< typename Block, typename AllocatorOrContainer >
|
||||||
|
template< typename CharT, typename Traits >
|
||||||
|
dynamic_bitset< Block, AllocatorOrContainer >::dynamic_bitset(
|
||||||
|
std::basic_string_view< CharT, Traits > sv,
|
||||||
|
size_type num_bits,
|
||||||
|
const allocator_type & alloc )
|
||||||
|
: m_bits( alloc ), m_num_bits( 0 )
|
||||||
|
{
|
||||||
|
init_from_string( sv.data(), sv.length(), 0, sv.length(), num_bits );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
template< typename Block, typename AllocatorOrContainer >
|
template< typename Block, typename AllocatorOrContainer >
|
||||||
template< typename BlockInputIterator >
|
template< typename BlockInputIterator >
|
||||||
@@ -2061,12 +2075,12 @@ template< typename Block, typename AllocatorOrContainer >
|
|||||||
template< typename CharT, typename Traits >
|
template< typename CharT, typename Traits >
|
||||||
void
|
void
|
||||||
dynamic_bitset< Block, AllocatorOrContainer >::init_from_string(
|
dynamic_bitset< Block, AllocatorOrContainer >::init_from_string(
|
||||||
const CharT * s,
|
const CharT * s, // caution: not necessarily null-terminated
|
||||||
|
std::size_t string_length,
|
||||||
std::size_t pos,
|
std::size_t pos,
|
||||||
std::size_t n,
|
std::size_t n,
|
||||||
size_type num_bits )
|
size_type num_bits )
|
||||||
{
|
{
|
||||||
const std::size_t string_length = Traits::length( s );
|
|
||||||
BOOST_ASSERT( pos <= string_length );
|
BOOST_ASSERT( pos <= string_length );
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -208,6 +208,10 @@ struct bitset_test
|
|||||||
// If M < N, remaining bit positions are zero
|
// If M < N, remaining bit positions are zero
|
||||||
for ( ; j < actual_size; ++j )
|
for ( ; j < actual_size; ++j )
|
||||||
BOOST_TEST( b[ j ] == 0 );
|
BOOST_TEST( b[ j ] == 0 );
|
||||||
|
|
||||||
|
#if defined( BOOST_DYNAMIC_BITSET_USE_CPP17_OR_LATER )
|
||||||
|
BOOST_TEST( Bitset( std::basic_string_view< Ch, Tr >( str ).substr( pos, rlen ), num_bits ) == b );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user