Skip to main content
Filter by
Sorted by
Tagged with
2 votes
0 answers
95 views

Usually I define my template classes as following (template<template<class> class T> is essential here): // Foo.h template<template<class> class T> class Foo { void foo(); ...
master_clown's user avatar
3 votes
2 answers
148 views

To create a C++ class template that takes a standard container as a template argument I would do something like #include <vector> template <template<typename U,typename A=std::allocator&...
Olof's user avatar
  • 133
3 votes
0 answers
167 views

In C++26, the following code is legal (see p2841r7 and Herb Sutter's article): template<typename<typename> concept C, template<typename> auto vt, typename T> requires C<T> auto ...
xmllmx's user avatar
  • 44.6k
-1 votes
1 answer
108 views

I have a function which takes a template template parameter, e.g.: template <template <typename K, typename V> typename Map> void foo(); I want to specify a default value for Map; namely, ...
einpoklum's user avatar
  • 137k
2 votes
1 answer
75 views

I'm building trait-types (similar to std::type_identity) to represent template-templates of the different flavors. Mixed-type variadic value templates are a special case, and I can only think of doing ...
xaxazak's user avatar
  • 998
1 vote
0 answers
44 views

I have this code perfectly working on clang template <template <typename, typename> typename T> struct CollectIntoAllocatedContainer { // ... }; template <template <typename, ...
burbokop's user avatar
1 vote
2 answers
94 views

I want to call different template member functions with the same sequence of input types, in order to reduce boilerplate code, I tried to implement a dispatcher function, for_each_type, struct A { ...
user416983's user avatar
  • 1,106
2 votes
1 answer
73 views

I have a class template taking a template template parameter template<template<class> typename T> struct S {}; and a class template taking 2 template parameters template<size_t i, ...
PyOPTProblem's user avatar
0 votes
1 answer
67 views

For a project I'm working on I have been trying to implement a typelist with template class.s as the possible types. The relevant parts of my implementation are below. It works well generally but it ...
Gemini Em's user avatar
0 votes
1 answer
92 views

There is a very similar question, but I did not understand how I could apply the workarounds to my code. It was more about achieving generality across different container types: Visual C++ cannot ...
typ1232's user avatar
  • 5,613
1 vote
0 answers
36 views

In C++20, is it possible for a concept to be templated on another concept? I can do template <typename R> concept RangeOfFloats = std::ranges::range<R> && std::floating_point<...
Ben's user avatar
  • 9,903
1 vote
1 answer
102 views

Imagine a library has class templates A and B: template <template <class> class T> class A; template <class T, class U> class B; Now, if a user of the library wants to pass B as an ...
lobelk's user avatar
  • 531
0 votes
1 answer
99 views

I'm trying to write a little template function that returns sequential integer id's for templates passed to it. The following works for many templates, but not for templates that take non-type ...
Matthew Busche's user avatar
1 vote
2 answers
93 views

I have two related types (duck-typing), and another one that provides similar functionality with a different interface: namespace a { template<typename T> struct A final {}; using ...
Ðаn's user avatar
  • 11k
1 vote
2 answers
69 views

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
111 views

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
  • 149
2 votes
3 answers
106 views

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,215
0 votes
1 answer
350 views

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
  • 591
1 vote
2 answers
2k views

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
  • 171
4 votes
1 answer
351 views

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
  • 287
0 votes
1 answer
427 views

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
  • 2,335
4 votes
0 answers
85 views

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
  • 5,374
5 votes
0 answers
65 views

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
  • 998
7 votes
1 answer
308 views

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
  • 78.1k
1 vote
2 answers
96 views

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
126 views

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
6 votes
3 answers
2k views

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
  • 7,875
2 votes
1 answer
1k views

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
2 votes
1 answer
414 views

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
123 views

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
  • 80
7 votes
1 answer
385 views

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,903
3 votes
0 answers
158 views

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
474 views

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
  • 5,374
-2 votes
1 answer
126 views

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
  • 51
6 votes
0 answers
44 views

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
413 views

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
46 views

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
1k views

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
43 views

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 << ...
arniiiii_ua's user avatar
1 vote
1 answer
753 views

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
  • 27.2k
8 votes
1 answer
715 views

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
  • 24.7k
0 votes
1 answer
72 views

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
298 views

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
  • 2,278
5 votes
3 answers
1k views

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
  • 967
1 vote
1 answer
869 views

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
276 views

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
145 views

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
5 votes
1 answer
2k views

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
  • 765
2 votes
1 answer
536 views

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
  • 30.9k
2 votes
2 answers
457 views

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,777

1
2 3 4 5 6