Boost logo

Boost :

Subject: [boost] [string_ref] string literal constructor
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-11-01 19:42:05


I noticed string_ref doesn't have a constructor for a string literal.
Wouldn't this save a call to strlen for a common case?

Ex.

template< std::size_t N >
basic_string_ref( const charT( &str )[N] )
     : basic_string_ref( str, N-1 )
{
     static_assert(N >= 1, "not a string literal");
}

string_ref test( "test" );

I see that adding this directly doesn't work as the compiler is always
choosing to decay and pick the const char* overload.

Is there no way to make this work?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk