Subject: Re: [boost] [string_ref] string literal constructor
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-11-01 20:00:31
On 11/01/2013 04:42 PM, Michael Marcin wrote:
> 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?
> 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?
The behavior is not guaranteed to be the same, anyway.
Not all char arrays are string literals.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk