I've some trouble to make use of template template parameters. Here is a very simplified example:
template <typename T> 
struct Foo {
  T t;
};
template <template <class X> class T>
struct Bar {
  T<X> data;
  X x;
};
int main()
{
  Bar<Foo<int>> a;
}
The compiler (g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2) reports the following error:
main.cpp:8:5: error: ‘X’ was not declared in this scope
   T<X> data;
     ^
main.cpp:8:6: error: template argument 1 is invalid
   T<X> data;
      ^
Any idea what's wrong?
8. Why we use :: template-template parameter? Explanation: It is used to adapt a policy into binary ones.
The first template parameter is the type of elements the container stores and the second template parameter is the defaulted allocator a container of the standard template library has. Even the allocator has a default value such as in the case of a std::vector. The allocator depends on the type of elements.
Templates in C++ is an interesting feature that is used for generic programming and templates in c++ is defined as a blueprint or formula for creating a generic class or a function. Simply put, you can create a single function or single class to work with different data types using templates.
Template parameters may have default arguments. The set of default template arguments accumulates over all declarations of a given template.
So I would like so make use of something like
Bar<Foo<>>
template <typename T = int> 
struct Foo {
  T t;
};
template <typename T>
struct Baz {
  T t;
};
template <typename T>
struct Bar;
template <template <typename> class T, typename X>
struct Bar<T<X>> {
  T<X> data;
  X x;
};
int main()
{
  Bar<Foo<>> a;
  Bar<Baz<float>> b;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With