Is there an existing (in the standard library or in Boost) type trait to test whether a type could represent a string?
I stumbled upon an issue when using Boost.Fusion:
auto number = fusion::make_vector( 1, "one" );
auto numberName = fusion::filter< char const * >( number );
assert( numberName == fusion::make_vector( "one" ) ); // fails
I hoped filter
would retain "one", but it failed because "one" is not decayed to a pointer (make_vector
takes its arguments by reference, so the type is const char (&)[4]
). Consequently, I need a trait that would allow me to write something like this:
auto numberName = fusion::filter_if< is_string< mpl::_ > >( number );
I am aware that a char const *
and a const char[N]
are not necessarily null-terminated strings, but it would still be handy to be able to detect them uniformly. The trait could also possibly return true
for std::string
and the likes.
Does such a trait exist or will I have to write my own?