On 03.08.2015 17:53, David Krauss wrote:
>
>> On 2015–08–03, at 2:41 PM, TheIdeasMan <
dancing...@gmail.com
>> At the moment the type_trait *is_char* is not part of the C++
>> standard, however boost does have it at:
>>
>> |#include <boost/spirit/home/support/string_traits.hpp>|
>>
>> The existing standard does have traits for basic types and generic
>> traits such as is_arithmetic , so
>> I was wondering if there was a reason for this not to be part of the
>> current standard, or is it a trivial ommision?
>
> Within the strings library, at least, character manipulation is done
> through specializations of std::char_traits. User-defined types can be
> “char-like,” but the builtin signed char and unsigned char have no
> char_traits specialization, so the operations don’t work.
>
> A standardization proposal should justify what criteria and common
> features unite “character types,” because signed char and char32_t have
> few use cases in common.
>
> As for the linked Boost header, it only blesses char and wchar_t, with
> no C++11 support. It might be good to find a better example.
I have a similar trait in Boost.Log:
https://github.com/boostorg/log/blob/master/include/boost/log/detail/is_character_type.hpp
The trait is useful when you want to write generic code that is supposed
to be used in the context of strings, like:
template< typename T >
typename enable_if< is_char< T >::value, basic_string< T > >
foo(const T* str);
Arrays of such types can be interpreted as C-style strings. As such you
should be able to use std::basic_string, string IO and character
manipulation (<ctype>, <codecvt>, etc.) with these types.
It's true that std::char_traits is only specialized for character types,
but you can't use this fact without getting hard compile errors. I
believe, std::char_traits should be described in terms of is_char
instead, i.e. be specialized for all types for which is_char returns true.