8

Which templates (if any) in the C++ standard library have one or more template template parameters?

If there are many, then a couple of examples is fine.

If C++ version matters, then the latest draft of C++14/C++1y is preffered.

7
  • Some templates of containers have template constructors. Commented Aug 28, 2014 at 22:01
  • 7
    @GingerPlusPlus: a constructor template is not a template template parameter. Commented Aug 28, 2014 at 22:01
  • I think there aren't template template parameters templates in STL. Because this would break the philosophy of Containers <-> Iterators <-> Algorithms. Commented Aug 28, 2014 at 22:05
  • 3
    @AndrewTomazos a quick ad-hoc peruse of the C++11 standard reveals no first-term template-template arguments (i.e. something of the form template<template<.... I didn't take the time to write up a full and proper RE to scan the entire standard, but I think 40two is perhaps correct, that no standard-lib actual usage exists. I don't have a v14 draft handy; sorry about that. Commented Aug 28, 2014 at 22:10
  • 1
    There aren't any because template template parameters are really awkward (especially before C++11) and the standard silently acknowledges that ;) Commented Aug 29, 2014 at 12:38

1 Answer 1

8

I'm not aware of any templates in the C++ standard library that are specified to take a template template parameter, but there is at least one standard template in C++11 that has a partial specialization with a template template parameter: std::pointer_traits. std::pointer_traits<Ptr>::element_type is specified to be:

Ptr::element_type if such a type exists; otherwise, T if Ptr is a class template instantiation of the form SomePointer<T, Args>, where Args is zero or more type arguments; otherwise, the specialization is ill-formed.

In order to implement this you need a template template parameter for SomePointer, because it can be an arbitrary class template (as long as it only has type template parameters, to be precise). Here is the libstdc++ helper class partial specialization that does this, for instance:

 template<template<typename, typename...> class _SomePtr, typename _Tp, typename... _Args> struct __ptrtr_elt_type<_SomePtr<_Tp, _Args...>, false> { typedef _Tp __type; }; 
Sign up to request clarification or add additional context in comments.

1 Comment

Strictly speaking an implementation must conform to the described behaviour, which in this case doesn’t explicitly mention a partial specialization. They can do so any which way so they could e.g. choose to perform magicks. In either case, the user is not allowed to detect whether such a specialization is present or not.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.