Article View: comp.std.c++
Article #2548Some questions about standard library
From: Kresimir Fresl
Date: Tue, 14 Nov 1995 01:23
Date: Tue, 14 Nov 1995 01:23
49 lines
3052 bytes
3052 bytes
I have few questions (or maybe themes for discussion) about some
design decisions in standard library. I started to read articles in
comp.std.c++ only recently, so maybe some of them were already discussed.
1. `struct pair <T1, T2>' has only one constructor:
pair(const T1& x, const T2& y).
As far as I know, compiler can generate copy constructor, but,
because there is one constructor, it can't generate default
constructor.
But then you can not do this:
vector < pair <int, int> > v (5);
because first default argument of constructor for `vector<T>' is a call
to default constructor of T. Some other `vector' member functions also
expect default constructor of T. So, I think that `pair' should also have
default constructor.
2. Return value of `binary_search()' is of type `bool'. I can't imagine
situation where someone would like to know if something is in container,
but not also the location of this something. Why return value is not
some kind of Iterator, as in `find()'?
3. `valarray' is also some kind of container, so it would be nice to use
some functions from algorithm library in the same way as for
`vector's etc.: `find()', `sort()' etc. But, `valarray' does not
have `begin()' and `end()' member function. Instead of `begin()' one
can use `operator T*()', but for `end()'? `operator T*()' + `length()'?
By the way: why `length()' and not `size()', as in other containers?
(What does `valarray' mean?)
4. Why is the return value of `valarray::operator[]() const' of type `T'?
Wouldn't `const T&' be better, to avoid call to copy constructor
of T? (`vector::operator[]() const' returns `const_reference').
5. Function `valarray::apply()' returns new `valarray'. But very often
you don't need old array any more, what means that you can change
values of its elements. This way you will avoid very expensive call
to copy constructor. Sometimes you don't even have enough memory to
construct whole new array. Therefore, there should be two functions,
one that constructs new array, and one that modifies elements of
existing array, as all computed assignments do.
fresl
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9511131915.AA00621@master.grad.hr>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 14 Nov 95 01:23:34 GMT Approved: fjh@cs.mu.oz.au Organization: - Newsgroups: comp.std.c++ X-Original-Date: Mon, 13 Nov 95 20:15:12 +0100 From: fresl@master.grad.hr (Kresimir Fresl) Message-ID: <9511131915.AA00621@master.grad.hr> Subject: Some questions about standard library X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMKfvveEDnX0m9pzZAQE27gF/eOJhmd7JvRPLgqaRuwyvoaoVQBghDOVK KFL0WnN/p+liHSD2sgch+PUXzZA/U6QR =zkcV