Initialization of std::vector<unsigned int> with a list of consecutive unsigned integers

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2012-01-13T18:11:24Z Indexed on 2013/06/25 10:22 UTC
Read the original article Hit count: 351

Filed under:
|
|

I want to use a special method to initialize a std::vector<unsigned int> which is described in a C++ book I use as a reference (the German book 'Der C++ Programmer' by Ulrich Breymann, in case that matters). In that book is a section on sequence types of the STL, referring in particular to list, vector and deque. In this section he writes that there are two special constructors of such sequence types, namely, if Xrefers to such a type,

X(n, t) // creates a sequence with n copies of t
X(i, j) // creates a sequence from the elements of the interval [i, j)

I want to use the second one for an interval of unsigned int, that is

std::vector<unsigned int> l(1U, 10U);

to get a list initialized with {1,2,...,9}. What I get, however, is a vector with one unsigned int with value 10 :-| Does the second variant exist, and if yes, how do I force that it is called?

© Stack Overflow or respective owner

Related posts about stl

Related posts about initialization