Friday, April 7, 2023

Digest for comp.lang.c++@googlegroups.com - 7 updates in 1 topic

Daniel <danielaparker@gmail.com>: Apr 06 06:27PM -0700

On Thursday, April 6, 2023 at 7:00:05 PM UTC-4, Sam wrote:
> strange alphabets came into existance, with all of those funny-looking
> characters that use the same octets, depending on which part of the world
> you happen to live in.
 
Indeed. If it ain't Yankee talk, it ain't talk.
 
Daniel
Bonita Montero <Bonita.Montero@gmail.com>: Apr 07 05:13AM +0200


> cout << strA << endl;
 
What about this:
 
#include <iostream>
#include <string>
#include <type_traits>
 
using namespace std;
 
template<typename Elem>
struct icase_traits : public char_traits<Elem>
{
using char_type = char_traits<Elem>::char_type;
private:
static constexpr Elem tolower( char_type c ) noexcept
{
return c < 'A' || c > 'Z' ? c : c - ('A' - 'a');
}
public:
static constexpr bool eq( char_type a, char_type b ) noexcept
{
return tolower( a ) == tolower( b );
}
static constexpr bool lt( char_type a, char_type b ) noexcept
{
return tolower( a ) < tolower( b );
}
static constexpr int compare( char_type const *s1, char_type const *s2,
size_t count )
{
for( size_t i = 0; i != count; ++i )
{
char_type
a = tolower( s1[i] ),
b = tolower( s2[i] );
if( a == b ) [[likely]]
continue;
if constexpr( is_integral_v<char_type> && sizeof(char_type) <
sizeof(int) )
return (int)a - (int)b;
else
return a < b ? -1 : 1;
}
return 0;
}
};
 
template<typename Elem, typename Alloc = allocator<Elem>>
using icase_string = basic_string<Elem, icase_traits<Elem>, Alloc>;
 
template<typename CharT, typename OTraits, typename Alloc>
basic_ostream<CharT, OTraits> &operator <<( basic_ostream<CharT,
OTraits> &str, icase_string<CharT, Alloc> const &out )
{
return str << out.c_str();
}
 
int main()
{
icase_string<char>
strA( "hello" ),
strB( "Hello" );
cout << (strA == strB) << endl;
cout << strA << endl;
}
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Apr 06 11:29PM -0700

On 4/6/2023 2:37 PM, Chris M. Thomasson wrote:
 
> #if ((UINT8_MAX != 255UL) || (CHAR_BIT != 8))
> #   error foobar
>

No comments: