Skip to content

vector_pro::vector_pro

C++
1
2
3
4
5
6
7
8
9
vector_pro();
vector_pro(const size_type len);
vector_pro(const size_type len, const value_type& val);
vector_pro(const_iterator_pro<value_type>from, const_iterator_pro<value_type>exclude_to);
vector_pro(const vector_pro<value_type>& another);
vector_pro(vector_pro<value_type>&& another);
vector_pro(const std::vector<value_type>& another);
vector_pro(const std::initializer_list<value_type> &another);
vector_pro(const value_type *arr, const size_type len);

Construct vector

Constructs a vector_pro, initializing its contents depending on the constructor version used:

  1. default constructor
    Constructs an container, with VECTOR_PRO_DEFAULT_SIZE.

  2. fill constructor
    Constructs a container with len elements. Each element is a copy of val (if provided).

  3. range constructor
    Constructs a container with as many elements as the range [from, exclude_to) and in the same order.

  4. copy constructor
    Constructs a container with a copy of each of the elements in another, in the same order.

  5. move constructor
    Constructs a container by moving each of the elements in another, in the same order.

  6. std::vector constructor
    Constructs a container with a copy of each of the elements in another, in the same order.

  7. initializer list constructor
    Constructs a container with a copy of each of the elements in another, in the same order.

  8. traditional array constructor
    Constructs a container with a copy of each of the elements in another, in the same order.

Parameters

  1. len
    Initial container size.
  2. val
    Value to fill the container with.
  3. another
    Another container object of the same type.
    Can be a std::vector , std::inializer_list or just another vector_pro.
  4. from, exclude_to
    Iterators to the initial and final positions in a range. The range used is [from, exclude_to), which includes all the elements between from and exclude_to , including the element pointed by from but not the element pointed by exclude_to.
  5. arr
    Traditional array.

Example

C++
// 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.