vector range constructor

{ edited by mod to shorten lines to ~70 characters. -mod }


currently, the vector constructor from two iterators is required for
at least forward iterators to first determine the size of the range
and then preallocate the vector to avoid reallocations during insertion.
For non-random-access iterators, this causes two traversals over the
range, which, if the iterators are "hard-working", for example filter
iterator adaptors over a large range, may up to double the running
time of the construction.

I would like to propose changing this to requiring only a single pass
over the range and dropping the requirement for preallocation for
non-random-access ranges. My thinking is that with the current wave of
data-generating, transforming and filtering ranges, traversing a range
may be arbitrarily expensive, while reallocating a vector must be cheap,
because moves should be cheap and otherwise the vector is the wrong
data structure to use to begin with.

This was certainly different at the time when the current vector
constructor requirements were written, but time has moved on.



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

8/19/2015 8:35:31 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

0 Replies

Similar Articles

[PageSpeed] 11


Similar Artilces:

type ranges for c,c++,java,c#
hi, is all the type range (int,float,double,...) for all languages same? Does anyone has URL of the type range for different languages? thank you On Tue, 30 Sep 2003 13:14:23 +0800, "smith flyers" <flyer@masfd.com> wrote: >hi, is all the type range (int,float,double,...) for all languages same? No. For C and C++ only minimum and relative ranges are defined for atomic types. However, C99 has a header that optionally defines exact size types. For Java and C# the ranges are exactly defined, and I believe they are the same for corresponding types. C# has unsigned inte...

vector constructors [was: realloc in c++]
<BEGIN QUOTED TEXT> | Hold on, I'm unconvinced again. Where did that (int, int) constructor | for vector<vector<int> > come from? It comes from the template constructor template<typename InputIterator> vector(InputIterator first, InputIterator last); which provides a best-match specialization | It works in the first compiler I | tried, but I that;'s because it's matching | vector( | size_type _Count, | const Type& _Val | ); No, this constructor cannot be used because in this case Type is vector<int> and the constructor tha...

Initializing a vector of a vector in a constructor
Hi all, I am attempting to initialize a vector of a vector in a constructor with some clean-looking syntax and am not sure of how to go about this. For instance: double weight; vector< vector<unsigned> > posInd; Table() : weight(0), posInd(???) {} Table(const TableEntry& o) : weight(o.weight), posInd(???) {} Table(double weight = 0.0, vector< vector<unsigned> > posInd) : weight(weight), posInd(???) {} Many thanks for your patience! fatgirl.br...@gmail.com wrote: > Hi all, > > I am attempting to initialize a vector ...

vector of vector of vectors
Hi, I'm having a problem that's driving me nuts right now. I wanted to represent data as a vector<vector<vector<unsigned short> > > Now I've been having alot of trouble initializing and accessing elements for that type. I can't seem to initialize like blah(10,10,10) to make each vector length 10, so instead I did blah(10,(10,10)) but even though that compiles I get runtime errors if I ever do something likeblah.at(i).at(j).at(k), no matter what the values of i j and k. Is there a clean way to do what I want it to do or should I just not try it this wa...

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta >...

Ruby, SWIG and C++: how to properly wrap vector of vectors of doubles (2D vectors)?
------=_Part_3942_18680883.1126720031081 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi All, I am succesfully using SWIG generated wreppers to export my C++ library to = Ruby. In my C++ library I extensively use nested C++ vectors like: typedef std::vector<double> DblVtr; //1D-vector (vector of doubles) typedef std::vector<DblVtr> DblVtr2; //2D-vector (vector of vectors of doub= les) When using SWIG genereted wrappers, I cannot figure out how to initialize 2D-vector from 2D Ruby arrays. v1=3D3D DblVtr.new ...

The C++ Language 4th edition
I was under the impression that it was generally a bad idea to subclass vector because the destructor is not virtual because if someone referenced an object of your class with a pointer and then deleted it with the base, the operation is undefined. In The C++ Programing Language Stroustrup says "... I often use a simple range-checking adaption of vector:" template<typename T> class Vec : public std::vector<T> { public: using vector<T>::vector; T & operator[](int i) {return vector<T>::at(i);} const T & op...

jython and C-c C-c
How do I get C-c C-c to work with jython? I have the jpython command set to jython, and I can start the interpreter with C-C ! and then use C-c C-c, but this is rather frustrating. If I try to use C-c C-c without first starting the interpreter in another window I get wrong type argument: sequencep, jpython Thanks, Dave Cook ...

vectorized computation in C++ such as those in Matlab (Matlab to C++)?
Dear all, Can C++/STL/Boost do the vectorized calculation as those in Matlab? For example, in the following code, what I really want to do is to send in a vector of u's. All other parameters such as t, l1, l2, l3, etc. are scalars... But u is a vector. Thus, t6 becomes a vector. t9 is an element-wise multiplication... The following code was actually converted from Matlab. If vectorized computation is not facilitated, then I have to call this function millions of times. But if vectorized computation is okay, then I can send in just a u vector with batch elements a time. I have man...

C++ STL vectors
Dear All, I'm learning STL vectors. So, excuse me for the dummy question. Suppose that, in some function, I create a foo() { vector<string> SS; } Is this vector deallocated at the end of the foo() function? If I want to pass it to some other function that will store it somewhere, do I need to use a vector * an allocate it someway and pass the pointer to the vector, instead the vector itself? Does it make any sense? If so, how do I do it? Thanks in advance. Best Regards, Jos� Augusto Jr. -- [ See http://www.gotw.ca/resources/clcm...

c++ primer statement about vectors containing vectors
C++ Primer by Lippman, Lajoie and Moo seems to object to code like std::vector<std::vector<double>> something; The concern is that >> will be interpreted as a shift operator and the code will not compile. However, I have seen no problems with this type of code and our company happily seems to accept code like the above with no spaces between the two > characters. Is the above code a real problem or not? Thanks, Paul Epstein pauldepstein@att.net wrote: > C++ Primer by Lippman, Lajoie and Moo seems to object to code like > std::vector<std::vector<double>...

c++98/c++03 constructor overloading
Hi, With gcc-4.2 and earlier, and with subsequent versions of gcc when using the -std=c++98 option, the following code fails to compile: -------------------------- #include <iostream> #include <ostream> enum ByRef {by_ref}; template <class T> class MyClass { T t; public: MyClass(const T& arg): t(arg) { // (1) std::cout << "Without ByRef tag" << std::endl; } MyClass(T arg, ByRef): t(arg) { // (2) std::cout << "With ByRef tag" << std::endl; } }; int ...

c------->c++ and c++------>c
We can write c program in turbo c++ editor.But reverse is not true why? i.e The program will not compile if u write c++ program in turbo c editor vim wrote: > We can write c program in turbo c++ editor.But reverse is not true why? > i.e The program will not compile if u write c++ program in turbo c > editor This isn't about C; this is about some editor. Why the fircone should /we/ know? Ask in a relevant group. [And /why/, in an editor specialised to some specific programming languages, would you expect it to compile a /different/ one? Would you expect turbo perl to compi...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

Web resources about - vector range constructor - comp.lang.c++.moderated

Von Neumann universal constructor - Wikipedia, the free encyclopedia
Three generations of machine are shown: the second has nearly finished constructing the third. The lines running to the right are the tapes of ...

Bridge Constructor Playground on the App Store on iTunes
Get Bridge Constructor Playground on the App Store. See screenshots and ratings, and read customer reviews.

Lewis Hamilton wins inaugural Russian Formula One Grand Prix as Mercedes take constructors' title
... Russian Formula One Grand Prix and extended his championship lead on Sunday in a Mercedes one-two that clinched the team's first constructors' ...

Observation wheel constructor vows to fight court writ
The construction company being sued for $6 million by the owner of the troubled Melbourne Star Observation Wheel has vowed to vigorously contest ...

Bill Shorten denies Winslow Constructors union payment deal disadvantaged workers after royal commission ...
Opposition Leader Bill denies lucrative deal he oversaw while union leader disadvantaged workers.

Chinese constructor resumes work after security assurance
Chinese constructor resumes work after security assurance People's Daily Online MOYALE, Kenya, Dec. 16 A Chinese roads construction firm, Wu ...

Colleagues Remember ‘Master Crossword Constructor’ Merl Reagle
Colleagues Remember ‘Master Crossword Constructor’ Merl Reagle

Apps of the Week: Hurricane, Bridge Constructor Medieval, Origami Live Wallpaper and more!
It's the last edition of Apps of the Week for the month of May, and we've pulled together a great list of apps from the folks here at Android ...

A Chance To Win Bridge Constructor For iPhone And iPad
... has teamed up with Headup Games , our latest AppAdvice Daily podcast sponsor, in order to offer you a chance to win a copy of Bridge Constructor ...

Price Drop: Monster Constructor
Monster Constructor 1.0 Device: iOS Universal Category: Games Price: Free, Version: 1.0 ( iTunes ) Description: Monster Constructor lets you ...

Resources last updated: 1/25/2016 8:13:23 AM