
"Thorsten Ottosen" <nesotto@cs.auc.dk> writes:
"David Abrahams" <dave@boost-consulting.com> wrote in message news:ur7g69ifb.fsf@boost-consulting.com... | "Thorsten Ottosen" <nesotto@cs.auc.dk> writes: | | > "Eric Niebler" <eric@boost-consulting.com> wrote in message | > news:428926DB.2090108@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