🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Kresimir Fresl Tue, 14 Nov 1995 01:23
Some questions about standard library
#2548
Author: Kresimir Fresl
Date: Tue, 14 Nov 1995 01:23
49 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads