Assume locales and std::use_facet() are always available

I think the days we needed to cope with their absence are gone.
This commit is contained in:
Gennaro Prota
2025-09-24 17:43:59 +02:00
parent 67115073d2
commit 6b5e49ea40
5 changed files with 19 additions and 65 deletions

View File

@@ -34,28 +34,6 @@ make_non_const( T t )
# define BOOST_DYNAMIC_BITSET_WRAP_CONSTANT( expr ) ( expr )
#endif
// A couple of macros to cope with libraries without locale
// support. The first macro must be used to declare a reference
// to a ctype facet. The second one to widen a char by using
// that ctype object. If facets and locales aren't available,
// the first macro is a no-op and the second one just expands
// to its argument c (in parentheses).
//
#if ! defined( BOOST_NO_STD_LOCALE )
# define BOOST_DYNAMIC_BITSET_CTYPE_FACET( ch, name, loc ) \
const std::ctype< ch > & name = \
BOOST_USE_FACET( std::ctype< ch >, loc ) /**/
# define BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, c ) \
( fac.widen( c ) )
#else
# define BOOST_DYNAMIC_BITSET_CTYPE_FACET( ch, name, loc ) /**/
# define BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, c ) ( c )
#endif
#if ! defined( BOOST_NO_CXX11_HDR_FUNCTIONAL ) && ! defined( BOOST_DYNAMIC_BITSET_NO_STD_HASH )
# define BOOST_DYNAMIC_BITSET_SPECIALIZE_STD_HASH
#endif

View File

@@ -25,14 +25,11 @@
#include <algorithm>
#include <climits>
#include <istream>
#include <locale>
#include <ostream>
#include <stdexcept>
#include <utility>
#ifndef BOOST_NO_STD_LOCALE
# include <locale>
#endif
namespace boost {
template< typename Block, typename AllocatorOrContainer >
@@ -1542,12 +1539,12 @@ template< typename B, typename A, typename StringT >
BOOST_DYNAMIC_BITSET_CONSTEXPR20 void
to_string_helper( const dynamic_bitset< B, A > & b, StringT & s, bool dump_all )
{
typedef typename StringT::traits_type Tr;
typedef typename StringT::value_type Ch;
typedef typename StringT::traits_type Tr;
typedef typename StringT::value_type Ch;
BOOST_DYNAMIC_BITSET_CTYPE_FACET( Ch, fac, std::locale() );
const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '0' );
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '1' );
const std::ctype< Ch > & fac = std::use_facet< std::ctype< Ch > >( std::locale() );
const Ch zero = fac.widen( '0' );
const Ch one = fac.widen( '1' );
// Note that this function may access (when
// dump_all == true) bits beyond position size() - 1
@@ -1590,9 +1587,8 @@ operator<<( std::basic_ostream< Ch, Tr > & os, const dynamic_bitset< Block, Allo
typename basic_ostream< Ch, Tr >::sentry cerberos( os );
if ( cerberos ) {
BOOST_DYNAMIC_BITSET_CTYPE_FACET( Ch, fac, os.getloc() );
const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '0' );
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '1' );
const Ch zero = os.widen( '0' );
const Ch one = os.widen( '1' );
BOOST_TRY
{
@@ -1684,9 +1680,8 @@ operator>>( std::basic_istream< Ch, Tr > & is, dynamic_bitset< Block, Alloc > &
typename basic_istream< Ch, Tr >::sentry cerberos( is ); // skips whitespace
if ( cerberos ) {
// in accordance with the resolution of library issue 303
BOOST_DYNAMIC_BITSET_CTYPE_FACET( Ch, fac, is.getloc() );
const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '0' );
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '1' );
const Ch zero = is.widen( '0' );
const Ch one = is.widen( '1' );
b.clear();
BOOST_TRY
@@ -2092,19 +2087,19 @@ dynamic_bitset< Block, AllocatorOrContainer >::init_from_string(
const std::size_t rlen = (std::min)( n, string_length - pos );
const size_type sz = ( num_bits != npos ? num_bits : rlen );
m_bits.resize( calc_num_blocks( sz ) );
m_num_bits = sz;
m_num_bits = sz;
BOOST_DYNAMIC_BITSET_CTYPE_FACET( CharT, fac, std::locale() );
const CharT one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '1' );
const std::ctype< CharT > & fac = std::use_facet< std::ctype< CharT > >( std::locale() );
const CharT one = fac.widen( '1' );
const size_type m = num_bits < rlen ? num_bits : rlen;
const size_type m = num_bits < rlen ? num_bits : rlen;
for ( std::size_t i = 0; i < m; ++i ) {
const CharT c = s[ ( pos + m - 1 ) - i ];
if ( Traits::eq( c, one ) ) {
set( i );
} else {
BOOST_ASSERT( Traits::eq( c, BOOST_DYNAMIC_BITSET_WIDEN_CHAR( fac, '0' ) ) );
BOOST_ASSERT( Traits::eq( c, fac.widen( '0' ) ) );
}
}
}

View File

@@ -23,16 +23,12 @@
#include <algorithm>
#include <assert.h> // <cassert> is sometimes macro-guarded :-(
#include <iterator>
#include <locale>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>
#if ! defined( BOOST_NO_STD_LOCALE )
# include <locale>
#endif
template< typename T >
using small_vector = boost::container::small_vector< T, 8 >;
@@ -91,20 +87,6 @@ private:
boost::filesystem::path m_path;
};
#if defined BOOST_NO_STD_LOCALE
template< typename Stream >
bool
is_one_or_zero( const Stream & /*s*/, char c )
{
return c == '1' || c == '0';
}
template< typename Stream >
bool
is_white_space( const Stream & /*s*/, char c )
{
return std::isspace( c );
}
#else
template< typename Stream, typename Ch >
bool
is_one_or_zero( const Stream & s, Ch c )
@@ -121,7 +103,6 @@ is_white_space( const Stream & s, Ch c )
{
return std::isspace( c, s.getloc() );
}
#endif
template< typename Stream >
bool

View File

@@ -21,7 +21,7 @@
# include <sstream>
#endif
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
#if defined BOOST_NO_STD_WSTRING
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
@@ -34,7 +34,7 @@ widen_string( const std::string & str, const std::locale & loc = std::locale() )
if ( len != 0 ) {
typedef std::ctype< wchar_t > ct_type;
typedef std::wstring::traits_type tr_type;
const ct_type & ct = BOOST_USE_FACET( ct_type, loc );
const ct_type & ct = std::use_facet< ct_type >( loc );
result.resize( len );
for ( std::size_t i = 0; i < len; ++i )

View File

@@ -23,7 +23,7 @@
# include <sstream>
#endif
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
#if defined BOOST_NO_STD_WSTRING
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif