
On Wed, Aug 28, 2013 at 4:16 PM, Antony Polukhin <antoshkka@gmail.com>wrote:
2013/8/28 Andrey Semashev <andrey.semashev@gmail.com>
A special char_trait type does change the type of string_ref, but it doesn't actually prohibit creating a string_ref from a non-literal string.
Hmmm, you are right. And how about this:
#include <boost/utility/string_ref.hpp> #include <string>
template <class Char, class Traits> class basic_string_literal: public boost::basic_string_ref<Char, Traits> { typedef boost::basic_string_ref<Char, Traits> base_t; public: template <std::size_t N> explicit basic_string_literal(const Char (&array)[N]) BOOST_NOEXCEPT : base_t(array, N) {} };
typedef basic_string_literal<char, std::char_traits<char> > string_literal;
Basically, that's what basic_string_literal is, except that the protection is a little more elaborate. The notable differences are that, unlike basic_string_ref, basic_string_literal doesn't allow to remove_prefix/suffix or substr and is always zero-terminated.