Relative Content

Tag Archive for c++templates

Passing a class template as a template template argument (C++)

In the following code, class template HANDLER is supposed to accept one template parameter F and one template template parameter P<R, S>. The base class IMPLEMENTATION is dependent to the parameters R and S. The way I declare class template HANDLER, I must pass the template arguments F,P, R and S individually in ‘HANDLER’ template list (see class BAR constructor). Isn’t there a way to pass class template ‘P<R, S>’ as a single parameter in the ‘HANDLER’ template list (see comment below class ‘BAR’ constructor) and still treat ‘R’ and ‘S’ as template arguments in the ‘HANDLER’ class? Thank you in advance, I am still new to C++ templates.

Accessing static member of nested template class

I have a templated class (Outer) and want to create a nested template class based on an enum of the class. This inner class has static variables, so they will need to be defined outside of the class to be accessible.

concept to check for absence of member

I want a concept that identifies when a template specialization has been performed. In other words, by default, it returns false, and only returns true if a customization has been done. I have successfully gotten this to work with the following code:

How to handle nested template classes with member functions of a template class

I’m trying to get more familiar with templates, specifically nesting of template classes. A very simple example to show what I’m after:
Assume we have a class Container, which has a data member field, a member function to mutate the data and a member function to print its contents. Here an implementation of this: