Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-05-17 10:20:37


"Thorsten Ottosen" <nesotto_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> wrote in message
> news:ur7g69ifb.fsf_at_boost-consulting.com...
> | "Thorsten Ottosen" <nesotto_at_[hidden]> writes:
> |
> | > "Eric Niebler" <eric_at_[hidden]> wrote in message
> | > news:428926DB.2090108_at_boost-consulting.com...
> | > |
> | > |
> | > | Yes. It's exactly the same situation. You are giving collection<X>
> | > | different semantics than collection<Y>.
> | >
> | > I guess my objection is to the use "exactly".
> | >
> | > If I have
> | >
> | > template< class T >
> | > class my_vec
> | > {
> | > std::vector<T> vec;
> | > };
> | >
> | > then I might need some traits for dealing with the bool case.
> |
> | What kind of traits?
>
> the kind of traits that you usually use when dealing with vector<bool>. :-)

I normally don't use any traits. That's part of what I've been trying
to say. If you write the generic code carefully, you can avoid the
non-uniformity and work on either kind of vector. Not so in your
case.

> maybe you would replace vector<bool> with vector<int> under the hood.

?? If someone passes me a vector<bool> I can't replace it.

> | > If I have
> | >
> | > template< class Range, class OutIter >
> | > void copy( const Range&, OutIter );
> | >
> | > then I just need to be able to say what a Range means.
> |
> | Yes, that's what makes your case worse. It doesn't just change the
> | interface details as with vector<T>, it changes the fundamental
> | meaning of T[N], leading to potential undefined behavior in some very
> | common cases.
>
> are you saying that the couldn't happen if we change the defaults?

If you take the whole statement above together, then yes, it couldn't
happen.

> Personally I don't care much about how most arrays are
> treated... but I do think having to write
>
> find( rng, as_string("foo") );
>
> is simply wierd and would be much more common than fiddling with
> fixed-sized arrays with various sentinels.

... for you. It's much less weird for me. Fixed-size arrays with
sentinels come up all the time in any code where the author wasn't
comfortable deducing array sizes, for example, in normal Python/C++
binding code. And the other case you have to consider -- also very
common -- is when you have fixed-size buffers of char that aren't
null-terminated strings.

Sometimes, to design a robust interface, it's neccessary to accept
that your experience and use cases aren't universal.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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