Boost logo

Boost :

Subject: Re: [boost] Data / String Ref library
From: Olaf van der Spek (olafvdspek_at_[hidden])
Date: 2011-04-02 08:27:43


On Tue, Mar 29, 2011 at 8:01 PM, Mathias Gaunard
<mathias.gaunard_at_[hidden]> wrote:
>>> Use boost::as_literal to construct an iterator_range from a string
>>> literal.
>>
>> Before: void f(const string&); f("Olaf");
>> After: void f(string_ref); f("Olaf");
>>
>> I do not want to change the API and I certainly don't want callers to
>> have to use boost::as_literal around every literal.
>
> Then do
>
> struct string_range : boost::iterator_range<const char*>
> {
>    string_range(const char* s)
>      : boost::iterator_range<const char*>(boost::as_literal(s))
>    {
>    }
>
>    string_range(const char* first, const char* last)
>      : boost::iterator_range<const char*>(first, last)
>   {
>   }
> };

You don't want to repeat that bit of code in every app / lib you write.

-- 
Olaf

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