Questions tagged [template-templates]

A mechanism for allowing templated C++ code to be parameterized not only over types and non-type values, but also over templates of types.

Filter by
Sorted by
Tagged with
1 vote
2 answers
51 views

Enforcing a common template type parameter among two template type parameters that are themselves templates

In C++, is there any way to ensure that two or more template type parameters are themselves template types with a common template type parameter? Let's say that I have this: struct ArbitraryType {}; ...
js87's user avatar
  • 13
4 votes
0 answers
77 views

Template template parameter with a concept - why does GCC reject it?

I'm writing a generic struct that is templated on another template. I want the inner template to only accept types that match a concept. template<template<std::regular> typename T> struct ...
samw's user avatar
  • 139
2 votes
3 answers
65 views

Deducing the size of an array when a template template parameter is used

A very simple method to find the number of elements in a template array is shown in the following discussion: How does this function template deduce the size of an array? I wanted to emulate the same ...
Vinod's user avatar
  • 1,041
0 votes
1 answer
92 views

Template Template Parameters - Invalid Explicitly Specified Argument

I am just learning how to work with template template parameters and am having trouble invoking a function. Compiler Error: candidate template ignored: invalid explicitly-specified argument for ...
Michael's user avatar
  • 583
0 votes
2 answers
296 views

C++: For loop index as constexpr / template parameter

Language & standard: C++17 What I hope to achieve: I have created a global array, say int List[someconstant], which is constexpr constructed ; as such, I can pass its entries as template ...
Sardine's user avatar
  • 153
3 votes
1 answer
105 views

Is an alias template considered the same template template parameter as the original template?

As I was playing around I stumbled over the following code snippet, which surprisingly doesn't match my expectations. #include <tuple> #include <type_traits> template <class... Ts> ...
DNKpp's user avatar
  • 277
0 votes
1 answer
170 views

Syntax for define a template that takes a template [duplicate]

I wanted to create a type that holds a generic type type, that, itself, is a template with one argument. So, if my type is called C, it could be summarized like C<T<U>>. So, I went for it: ...
Alex Vergara's user avatar
  • 1,843
3 votes
0 answers
63 views

Allow metafunction to take templates with non-type and type template arguments regardless

I created a is_specialization_of concept based on the type traits found here. The concept checks if a type is a specialization of a certain template. Those work well in all cases where I just have ...
glades's user avatar
  • 3,935
5 votes
0 answers
60 views

Expansion of variadic type parameters of outer struct within member struct's template-template parameter

If you have a template struct then you can use T as the type of a value parameter of a member template: template <typename T> struct SMoo { template <T I, typename T2> ...
xaxazak's user avatar
  • 748
7 votes
1 answer
269 views

Is a template with reference non-type template parameter supposed to match a template template parameter with an auto non-type template parameter?

template<template<auto> class> struct A {}; template<int&> struct B {}; A<B> a; int main() {} All three compilers MSVC, GCC and Clang in their latest versions accept ...
user17732522's user avatar
  • 59.1k
1 vote
2 answers
56 views

c++ template template syntax: simplicity vs useability why not 'auto'

first code below compiled fine after sweating with the word 'class' five times in one line, and definition in "main" of shelf<std::vector, int> top_shelf; looks too fragmented to me, ...
Ammar Tamimi's user avatar
0 votes
1 answer
66 views

static member definition outside class template template

I'm getting: error: default argument for template parameter for class enclosing 'ticker<T, E, A>::garbage_element' 51 | E ticker<T,E,A> ::garbage_element; | ^~~~~...
Ammar Tamimi's user avatar
5 votes
3 answers
269 views

Can C++ template template parameters accept templates that take non-type parameters?

I have a function like this to implement fmap for C++: // Given a mapping F from T to U and a container of T, return a container of U // whose elements are created by the mapping from the original ...
jacobsa's user avatar
  • 5,789
2 votes
1 answer
571 views

C++ Template queue with template class

My template queue is below template <typename T> class LockingQueue { private: std::queue<T> s_queue; public: void push(T const& value) {} T pop() {} }; And my ...
Michael Liu's user avatar
1 vote
1 answer
124 views

c++ - passing standard container as a template template parameter

So, I need to make a mixin class that would encapsulate children of some derived class. The derived class should inherit from the mixin while providing a container template as a template template ...
Anton Tretyakov's user avatar
1 vote
2 answers
81 views

Cascade variadic template template parameters

How can I cascade variadic types? I.e.: template <typename... T> using Cascade = ???; // T1<T2<T3<...>>> Example: using Vector2D = Cascade<std::vector, std::vector, double&...
Roman's user avatar
  • 70
7 votes
1 answer
241 views

Exact rules for matching variadic template template parameters in partial template specialization

While creating this answer for another question I came around the following issue. Consider this program (godbolt): #include <variant> #include <iostream> template <typename T> ...
Jakob Stark's user avatar
  • 3,431
3 votes
0 answers
105 views

Is there a way to typedef a template template argument similar to typedef a template argument

I'm wondering if there is or will be a way in C++ which allows to typedef a template template argument similar to typedef a template argument. The only way i know of at the moment is using an alias ...
ridilculous's user avatar
2 votes
0 answers
346 views

Deduce template parameter of class member from constructor of class

I have a class A which contains a templated member B whose exact type should be deduced from A's constructor. The way this is supposed to work is that, as shown in the below example, B can be ...
glades's user avatar
  • 3,935
-2 votes
1 answer
116 views

C++20 Pass Familiar Template lambda as Class Template to Template Parameter of a Class

Consider passing a callable class template as a template parameter to some class. Three approaches as below but only functor one works. The naive template function failed because it cannot serve as a ...
Nkk's user avatar
  • 53
6 votes
0 answers
42 views

Try to remember template template argument passed into template for later re-use [duplicate]

I have a question that seems to be about template template arguments. Following code (life code on GodBolt.org) compiles with GCC up to 11.2, but it does not compiles with Clang++ up to 13.0.1. The ...
chi's user avatar
  • 309
2 votes
2 answers
277 views

Compile-time map on a type list

I am looking for an idiomatic way to apply a type-level transform for each element in a type list. So far I came up with the following, which works as expected: namespace impl_ { template <template ...
Pavel Kirienko's user avatar
2 votes
0 answers
40 views

Template class inheritance from template types while passing itself [duplicate]

Can someone please explain what is going on in the code below: template<class Thermo, template<class> class Type> class thermo : public Thermo, public Type<thermo<Thermo, ...
Ryan.'s user avatar
  • 21
1 vote
2 answers
668 views

Using a type without template arguments as a template argument

I have a class named Registry which correlates an ID with some data. I would like to make it so the underlying structure which stores these pairs can be any std::mapish type, of which the user can ...
Icedude_907's user avatar
0 votes
0 answers
40 views

template-determined class as return-type of a template function, that uses template template parameters

I have std::vector<double> , and my type Array-like. Also, there are a lot of numbers in std::vector<double> source, and I would like to make this code work in the way: std::cout << ...
kileatb's user avatar
  • 35
1 vote
1 answer
585 views

Issue with variadic template template parameter pack

Consider the following example: template< class A, int B, class C> struct Obj { A a_obj; static constexpr int b_value = B; C c_obj; }; template< template<class... > class ... ...
lurscher's user avatar
  • 26.2k
8 votes
1 answer
340 views

Why is the concept in template template argument not verified?

C++20 allows the program to specify concept for template template argument. For example, #include <concepts> template <typename T> concept Char = std::same_as<T, char>; template <...
Fedor's user avatar
  • 17.7k
0 votes
1 answer
47 views

Compare templates itselves and not instantiated template-types

My goal is to be able to compare templates i.e. write something like this template<typename T> struct template_type; template<template <typename...> typename TTmpl, typename ...Ts> ...
Dmitry Katkevich's user avatar
1 vote
2 answers
239 views

Why is there no variable template template parameter?

I'm planning to create a variable template that takes (variable) template-template parameter and one typename: template <template <typename> auto MetaPredicate, typename T> constexpr bool ...
Desmond Gold's user avatar
  • 1,557
4 votes
3 answers
809 views

Get number of template parameters with template template function

I'm not sure if this is possible, but I would like to count the number of template arguments of any class like: template <typename T> class MyTemplateClass { ... }; template <typename T, ...
Myon's user avatar
  • 937
0 votes
1 answer
357 views

Template default argument

How do I specify a template class as a default value for a template typename? e.g. the following doesn't work. template <typename A, typename B> class X {}; template <typename T=template <...
user3689963's user avatar
1 vote
1 answer
133 views

Is it possible to deduce template template parameter parameter (no typo :-) )

I have a class which implements data types for a huge project. I simplify it here to (actually it is a subclass passing typeID and subTypeID to iots parent class constructor): template<typename T,...
Gaston's user avatar
  • 115
3 votes
1 answer
119 views

What "conversion" of template template parameters is allowed in C++?

I'm trying to understand under what circumstances I can pass a type template as an argument for a template template parameter with a different signature. E.g., I would expect that the following might ...
Sam Marinelli's user avatar
4 votes
1 answer
2k views

Visual C++ cannot deduce template template parameter

The following snippet of C++17 code compiles in GCC and CLang, but in Visual C++ it gives these errors: <source>(14): error C2672: 'f': no matching overloaded function found <source>(14): ...
Arjonais's user avatar
  • 573
2 votes
1 answer
429 views

Do C++20 concepts enable fixing template function as template argument problem?

If you try something relatively simple in C++20 it implodes with unhelpful error message spam. int main() { auto as = std::vector{1,3,24,}; auto bs = std::vector{1,4,10}; auto cs = std::...
NoSenseEtAl's user avatar
  • 28.6k
2 votes
2 answers
308 views

How to get at a C++ Container<T>'s T if no Container::value_type is provided?

It's rather common that container templates contain a value_type typedef. This makes it easy to create other templated code, most recently concepts, which are able to extract the T if only having been ...
Qqwy's user avatar
  • 5,299
1 vote
1 answer
60 views

Simpler syntax to bind some parameters to a template template paramater

A class ExpectTTs takes a number of template template parameters: template< template<typename> class... TT > struct ExpectTTs {}; Another type requires two template parameters. I need to ...
Helloer's user avatar
  • 427
4 votes
1 answer
164 views

Passing a template's template member type as a template template argument

A class WithTTMember has a template member type named TT. struct WithTTMember { template<typename> using TT = void; }; Another class ExpectTT takes a template template parameter: template&...
Helloer's user avatar
  • 427
0 votes
1 answer
107 views

How to specialize a nested class for template template parameter of the enclose class

Given: template<typename T> struct Foo { template<typename U> struct Bar {}; /* many more members */ } and template<typename F> struct Zoo {}; I need that only Bar ...
audi02's user avatar
  • 569
3 votes
1 answer
78 views

Is there a workaround for template template arguments being invisible?

Consider the following code: template<typename... Args1> constexpr size_t direct = sizeof... (Args1); template<template<typename... Args1> typename A1> constexpr size_t nested = ...
NoSenseEtAl's user avatar
  • 28.6k
1 vote
2 answers
142 views

Is it possible to specialize a method of a template class on another templated class?

I have a class A that is a template, and I want to specialize the method foo() if the class is a std::vector<T> with T generic, I am getting the error: invalid use of incomplete type. I'd like ...
lucmobz's user avatar
  • 473
2 votes
2 answers
408 views

Extract first template parameter from a template template parameter and using it inside the class?

I have the following problem: a class template A with several template parameters, I want to build a class B that takes A as template parameter and extract the first template parameter of A in order ...
lucmobz's user avatar
  • 473
2 votes
1 answer
64 views

partial specialised template as template argument

let's say for example I have a function foo() taking a parameter pack Ts. The function however should only accept the parameter pack Ts if there is exactly one type meeting the requirements of std::...
user3520616's user avatar
0 votes
3 answers
73 views

If template parameter AA is a templatized class A<T> itself, is it possible to get the template parameter (T) of this templatized class?

Consider the code below: template <typename T> class A{ ... } template <class U> class B{ ... } int main { B<A<int>> a; ... } How can I get the template parameter of A (int ...
KMot's user avatar
  • 477
4 votes
2 answers
353 views

template non-type template parameter

I am trying to write a constexpr constant concisely using C++20 features. #include <utility> template <template <typename T, T ... Ints> std::integer_sequence<T, Ints...> I> ...
Arjonais's user avatar
  • 573
4 votes
2 answers
458 views

How to match only variadic templates with a template template parameter?

Consider the following code: #include <iostream> template <template<class...> class C> struct foo { foo() { std::cout << "base case\n";} }; template <...
463035818_is_not_an_ai's user avatar
2 votes
1 answer
311 views

Template Class that takes a Template Class that Takes a Concrete Class

While I've seen a few posts regarding taking in template classes as a parameter into a template class I can't seem to find something that works with my code, or simply I do not understand the ...
SomeCoder's user avatar
2 votes
2 answers
415 views

Why compiler cannot deduce template template argument?

I want to write a function that takes a generic container with any type and prints it. Let's leave for a moment that it won't work for some associative containers and focus on the issue: template<...
Eduard Rostomyan's user avatar
0 votes
1 answer
67 views

Template template parameter and template alias: compiler bug?

I have got problem with the following representative sample code: template<int I> struct X {}; template<int I> struct Y {}; template<int I> struct XX: X<I> {}; template<...
janou195's user avatar
  • 1,175
2 votes
1 answer
310 views

C++: Template Template Member of a Template Parameter as a Parameter to a Template Class Expecting a Template Template parameter

First of all, apologies for the horrible title. I was experimenting with the C++20 is_detected functionality. is_detected basically takes two template parameters, one is a higher-order type which ...
jnbrq -Canberk Sönmez's user avatar

1
2 3 4 5 6