关于std::bitset的构造函数的几个问题?

Several questions about constructors of std::bitset?

来自 cppreference

#3

template< class CharT, class Traits, class Alloc >

explicit bitset( const std::basic_string<CharT,Traits,Alloc>& str,
                 typename std::basic_string<CharT,Traits,Alloc>::size_type pos = 0,
                 typename std::basic_string<CharT,Traits,Alloc>::size_type n =
                     std::basic_string<CharT,Traits,Alloc>::npos);                                                    (until C++11)

template< class CharT, class Traits, class Alloc >

explicit bitset( const std::basic_string<CharT,Traits,Alloc>& str,
                 typename std::basic_string<CharT,Traits,Alloc>::size_type pos = 0,
                 typename std::basic_string<CharT,Traits,Alloc>::size_type n =
                     std::basic_string<CharT,Traits,Alloc>::npos,
                 CharT zero = CharT('0'),
                 CharT one = CharT('1'));                                                                                             (since C++11)
template< class CharT >

#4

explicit bitset( const CharT* str,
                 typename std::basic_string<CharT>::size_type n =
                     std::basic_string<CharT>::npos,
                 CharT zero = CharT('0'),
                 CharT one = CharT('1'));                                                                                            (since C++11)

我有几个问题:

  1. 对于#3#4,为什么标准指定std::basic_string<...>而不是std::string?我知道 std::string 也称为 std::basic_string<char>,其他字符类型如 wchar_tchar16_t 可以应用于 std::basic_string<...>。但我觉得没必要,因为bitset包含01,正如它的名字所示。

  2. 老实说,我对string不是很熟悉class:为什么要加#4const CharT*能做什么,std::basic_string<CharT,Traits,Alloc>做不到?

#3 对于使用宽字符的人来说很方便——你不能指望人们将他们的宽字符串“0"s and "1”转换为窄字符串以使用基于字符串的构造函数只是因为您碰巧知道这些值总是二进制的——否则这个构造函数应该被一个 1 位宽的字符串变体替换。换句话说,写的更方便,那么去掉那个方便有什么好处呢?

#4 适用于拥有字符串文字或指向字符数组的指针的人,这样他们就不需要构造无用的临时文件 std::string.