vector_pro::vector_pro¶
Construct vector¶
Constructs a vector_pro, initializing its contents depending on the constructor version used:
-
default constructor
Constructs an container, withVECTOR_PRO_DEFAULT_SIZE. -
fill constructor
Constructs a container withlenelements. Each element is a copy ofval(if provided). -
range constructor
Constructs a container with as many elements as the range[from, exclude_to)and in the same order. -
copy constructor
Constructs a container with a copy of each of the elements inanother, in the same order. -
move constructor
Constructs a container by moving each of the elements inanother, in the same order. -
std::vector constructor
Constructs a container with a copy of each of the elements inanother, in the same order. -
initializer list constructor
Constructs a container with a copy of each of the elements inanother, in the same order. -
traditional array constructor
Constructs a container with a copy of each of the elements inanother, in the same order.
Parameters¶
len
Initial container size.val
Value to fill the container with.another
Another container object of the same type.
Can be astd::vector,std::inializer_listor just anothervector_pro.from,exclude_toIteratorsto the initial and final positions in a range. The range used is[from, exclude_to), which includes all the elements betweenfromandexclude_to, including the element pointed byfrombut not the element pointed byexclude_to.arr
Traditional array.
Example¶
// constructing vectors
#include <iostream>
#include "vector_pro.h"
/**
* Output:
* The contents of fifth are: [ 100, 100, 100, 100 ]
* While in fourth will be: [ null ]
*/
int main () {
// constructors used in the same order as described above:
// empty vector_pro of ints
vector_pro<int> first;
// four ints with value 100
vector_pro<int> second (4,100);
// iterating through second
vector_pro<int> third (second.begin(),second.end());
// a copy of third
vector_pro<int> fourth (third);
// a `move` from fourth
vector_pro<int> fifth (std::move(fourth));
std::cout << "The contents of fifth are: " << fifth << std::endl;
std::cout << "While in fourth will be: " << fourth << std::endl;
// a copy from std::vector
std::vector<int> myints = {1, 2, 3, 4, 5};
vector_pro<int> sixth (myints);
// a copy from initializer list
vector_pro<int> seventh = {1, 2, 3, 4, 5};
// a copy from traditional array
int arr[5] = {0, 1, 2, 3, 4};
vector_pro<int> eighth (arr, 5);
return 0;
}
Complexity¶
Constant for the default constructor (1), and for the move constructors (3) .
For all other cases, linear in the resulting container size.