Wednesday, August 16, 2017

C++11: Template Aliases

You can create Template that renames another template, but with some template parameters filled in. Here is an example:

template<class T, class U, class V>
struct MyTemplate {T t; U u; V v;};

template<class T>
using MyTemplateUV =  MyTemplate<T, int, float>;

MyTemplateUV<int>           s = {1, 2, 3.0};
MyTemplate  <int,int,float> t = {4, 5, 6.0};

int main()
{
  t = s;
  return 0;
}

Reference: https://isocpp.org/wiki/faq/cpp11-language-templates#template-alias

No comments:

Post a Comment