Subject: Re: [boost] Heads up - string_ref landing
From: Yanchenko Maxim (maximyanchenko_at_[hidden])
Date: 2012-11-16 03:03:03
16.11.12, 10:30, "Antony Polukhin":
> Better then other names, but at first glance it is not clear, that
> char_range can be used as string.
Depends on what you understand by string. It can't grow, for example.
No name can embrace all features.
> > 3. It's worth having a static constructor 'literal' (templated with size) to construct
> > char_ranges from literals - as the compiler knows their size in compile time (minus
> > zero terminator). It can be a constexpr too.
> > Same manner - static function 'from_array', embrasing an array of chars in whole,
> > assuming there is no zero terminator - useful for working with structures
> > representing messages in char-based protocols with fixed-width fields.
> Instead of 'literal' I'd propose a following constructor:
> template <size_type N>
> explicit string_ref(const Char (&str)[N]);
See the difference:
char_range(s); // size 2 because of strlen inside, runtime
char_range::literal( "ab\0c" ); // size 4, compile time
char_range::from_array(s); // size 20, compile time
char_range::from_array( "ab\0c" ); // size 5, compile time
> As I know, lots of people are unhappy with current design of
> std::basic_string. They think that it has too many member functions in
> it. If those functions were also implemented as free, more containers
> would be able to reuse them (they can be reused by basic_string
> implementation in Boost.Containers, by string_ref implementation). May
> be authors of Boost.StringAlgo, Boost.Container, Boost.StringRef
> cooperate for better code reuse?
I believe Boost.StringAlgo already does the job.