Extract container template for storing a different type

  Kiến thức lập trình

Given a container of a certain type as input, is it possible to “extract” the container template and instantiate it for a different type? For example:

void f ( auto& x ) {
  getContainerTemplate(x)<int> a (10); // getContainerTemplate() 
  // is some magic function.
}

The effect of f() should be the following depending on the type of x:

void f ( std::vector<double>& x ) {
  std::vector<int> a(10);
}

or

void f ( parlay::sequence<double>& x ) { // parlay::sequence is
  // another container template storing elements contiguously.
  parlay::sequence<int> a(10);
}

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT