Boost logo

Boost :

Subject: Re: [boost] [c++TR2] N3334, Proposing array_ref<T> and string_ref
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2012-01-30 09:30:21


2012/1/30 Beman Dawes <bdawes_at_[hidden]>

> One of my blink reactions is that array_ref<T> and
> basic_string_ref<charT, traits> are range generators and I was a bit
> surprised to see the implementation was a pointer and length rather
> than two pointers.

Implements are free to use two pointers if that's faster on some platform.

> Or better yet, two iterators or an explicit range
> component. With iterators, a basic_string_ref could do encoding
> conversions on-the-fly without need of temporary strings. But I have
> no idea if that is workable or actually is better.
>

I don't see how this could work unless each access to basic_string_ref
involves a virtual function call or all functions accepting
basic_string_ref must be templates.

// Writes a string to file. This function doesn't care who owns
// the string.
void WriteToFile(basic_string_ref<char, ...> s);

What should go in ... if the string is allowed to do encoding conversion
on-the-fly?

This is the same problem we have with ranges. If you want to write a
function that accepts a range of integers, you either have to implement it
as a template or use any_iterator/any_range which could be too inefficient.

Roman Perepelitsa.


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