|
Boost : |
Subject: Re: [boost] [utility] Proposal to extract some components from Boost.Log
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-08-28 08:27:15
On Wed, Aug 28, 2013 at 4:16 PM, Antony Polukhin <antoshkka_at_[hidden]>wrote:
> 2013/8/28 Andrey Semashev <andrey.semashev_at_[hidden]>
>
> > 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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk