template-templates Questions

1

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 ...

3

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 ...
Defection asked 3/11, 2022 at 0:56

1

Solved

While creating this answer for another question I came around the following issue. Consider this program (godbolt): #include <variant> #include <iostream> template <typename T> s...

1

Solved

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 ...
Lidstone asked 2/8, 2021 at 13:22

3

Solved

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, ...
Muro asked 17/6, 2021 at 12:22

1

Solved

Why this construction doesn't work? Visual Studio shows error C3201: the template parameter list for class template 'AA' does not match the template parameter list for template parameter 'C'. But ...
Aragats asked 15/2, 2017 at 13:36

1

Solved

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 mig...
Ulmaceous asked 24/4, 2021 at 2:50

2

Solved

Is this legal C++? template <typename T, template <typename T> class> struct S { }; Clang (3.7.1) rejects it, complaining the second T shadows the first T. GCC seems not to care abou...

0

The context This question asked if it is possible to write a trait that can retrieve the template from a given instantiation. In a nutshell the question was: "Is it possible to write a f suc...
Verbal asked 17/4, 2020 at 20:21

2

I have code that finds and prints out matches of a pattern as going over the container of strings. Printing is performed in the function foo that is templated The code #include <iostream> #...

1

Solved

The following nonsensical example does not compile, but is there some other way to pass a variable template as a template template argument? template<typename T> constexpr auto zero = T{0}; ...

10

Solved

I've seen some examples of C++ using template template parameters (that is templates which take templates as parameters) to do policy-based class design. What other uses does this technique have?
Humor asked 17/10, 2008 at 20:38

2

Solved

I have a class that needs to use some sort of map. By default, I want to use std::map, but I also want to give the user the ability to use something different if they want (e.g. std::unordered_map ...
Subadar asked 6/12, 2014 at 15:24

2

Solved

Visual Studio doesn't see the right constructor when I instantiate the template class. Where did I make a mistake? I've already tried to make copy/move constructors explicit/deleted. Doesn't help....
Celestina asked 1/8, 2019 at 13:53

1

Solved

I try to create template alias which cannot be distinguished from original. So, I create traits to check when 2 templates (not types) are equal: template <template <class...> class C1, ...
Twowheeler asked 6/5, 2019 at 18:35

1

Solved

The title is a bit confusing but what I mean is this specific case: template<class> struct get_type_of_nontype; template<class T, T Value, template<T> class Template> struct get...
Hysterectomy asked 6/3, 2019 at 23:11

5

I would like to implement a wrapper around a function call that would do something like this: template <template<class> class F> void Wrapper(int n, F&& f) { switch (n) { ca...
Saccharometer asked 18/10, 2018 at 14:13

3

This code: #include <memory> template <template <typename> class Ptr> class A { Ptr<int> ints; }; using B = A<std::unique_ptr>; yields the following error (with G...

2

Solved

I'd like to write a template function that iterates over a container of std::pair and returns a templated value with both types in the pair. I've gotten this to work for std::map as follows: templ...
Psychiatry asked 12/6, 2018 at 22:11

1

Solved

Consider the following code: template<typename T> struct A { }; // same as A, but with one extra defaulted parameter template<typename T, typename F = int> struct B { }; templa...
Ruprecht asked 6/2, 2018 at 14:23

1

Solved

Background Yesterday I asked a question about the guarantees of deduction guides usage in case of template template parameters. I was really surprised when Barry changed his answer to the confirma...

1

Solved

After a while I discovered again a power of template template-parameters. See e.g. the following snippet: template <template <class> class TT, class T> void foo(TT<T>) { } templ...
Jovia asked 8/10, 2017 at 11:58

1

Yet another decltype(auto) template template-parameter question. This time minimal code I was able to create to reproduce the error looks like this: template <template <decltype(auto)> cl...
Shoreless asked 20/9, 2017 at 17:9

1

Solved

I want to determine the underlying template of a template parameter by using a combination of a template alias and template specializations. The follwing code compiles fine on gcc 4.8, 6.2.1 but no...
Aestivation asked 12/9, 2016 at 20:48

3

There may be many case in which we want to perform some operation on a std::map or a std::unordered_map that is exactly the same, independently from the type of the map. Let us consider the followi...
View asked 9/8, 2017 at 21:48

© 2022 - 2024 — McMap. All rights reserved.