Questions tagged [template-aliases]
67 questions
11
votes
1 answer
Template aliases conflicting types. g++ compiles successfully while clang fails
I encountered a very strange compiler error. For some reason the posted code does compile properly with g++ (7.3.0) while clang (7.0.0) fails:
../TemplateAlias/main.cpp:64:9: error: no matching function for call to 'freeFunc'
freeFunc(new…

srohmen
- 223
- 1
- 9
10
votes
1 answer
How to emulate deduction guides for template aliases?
Consider the following:
template
struct my_array
{
T values[N];
};
We can provide deduction guides for my_array, something like
template
my_array (Ts ...) -> my_array,…

lisyarus
- 15,025
- 3
- 43
- 68
10
votes
1 answer
Template alias, Template specialization and Template Template parameters
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 not on clang 3.5, 3.8.
#include
template…

Benjamin Westrich
- 103
- 5
10
votes
1 answer
Alias template, partial specialization and the invalid parameter type void
Consider the following code:
template
struct S;
template
struct S { };
template
using Alias = S;
int main() {
S s;
Alias…

skypjack
- 49,335
- 19
- 95
- 187
10
votes
1 answer
Identity of template aliases
Let's consider a set of template aliases:
template using foo = T*;
template using bar = T*;
template using buz = foo;
template< templateclass TT > struct id {};
using id_foo = id;
using id_bar =…

Nickolay Merkin
- 2,673
- 1
- 16
- 14
10
votes
1 answer
template template alias to a nested template?
Template aliases are very convenient in simplifying types like typename F ::type to just F , where T and type are types.
I would like to do the same for templates like F ::map, i.e., simplify them to F , where T and map are template…

iavr
- 7,547
- 1
- 18
- 53
10
votes
1 answer
Another case where whitespace matters (maybe?)
Is this another case, where whitespace matters in C++, or is it a compiler bug? Is the following code syntactically correct?
#include
template
using EnableIf = typename std::enable_if::type;
template

TommiT
- 609
- 3
- 9
10
votes
1 answer
Is substitution failure an error with dependent non-type template parameters?
Let's say I have these template aliases:
enum class enabler {};
template
using EnableIf = typename std::enable_if::type;
template
using DisableIf = typename std::enable_if::type;
I…

R. Martinho Fernandes
- 228,013
- 71
- 433
- 510
9
votes
2 answers
C++11 template alias as template template argument leads to different type?
We have observed a strange behaviour in the compilation of the follwing source code:
template class TT> struct X { };
template struct Y { };
template using Z = Y;
int main() {
X y;
X z;
z = y; // it…

craffael
- 373
- 1
- 10
8
votes
1 answer
Why doesn't the alias template in function parameter match the nested type it refers to?
This code compiles
template
struct A {
struct Inner {} inner;
void foo(Inner in);
};
template
void A::foo(typename A::Inner in) {
}
int main() {
A a;
a.foo(a.inner);
}
And it won't if I change…

H.Wei
- 103
- 6
8
votes
1 answer
Is there a way to deduce alias templates to template template parameter while still preserving its property of being deduced context
After a while I discovered again a power of template template-parameters. See e.g. the following snippet:
template class TT, class T>
void foo(TT) {
}
template
using typer = T;
int main() {
…

W.F.
- 13,888
- 2
- 34
- 81
8
votes
1 answer
Why can't I declare templated type aliases inside of functions?
Why can't I declare a templated type alias inside of a function?
#include
int main(){
//type alias deceleration:
template
using type = std::vector;
//type instantiation:
type t;
}
error: a…

Trevor Hickey
- 36,288
- 32
- 162
- 271
8
votes
1 answer
Deprecate templated class name with template alias (type alias, using)?
I want to rename a templated class. To make the transition easier for the users, I'd like to keep the old class for one more version and mark it deprecated with the extensions from GCC / Clang (attribute deprecated).
To avoid keeping an exact copy…

usr1234567
- 21,601
- 16
- 108
- 128
7
votes
2 answers
C++ template alias (using) in specific places
I need to use type aliases via using (or any other method) in situations like this:
template
typename std::enable_if< /*HERE*/>::value
f (...) {};
Where I wrote HERE there are long and more than one types defined inside structures, and…

bolov
- 72,283
- 15
- 145
- 224
7
votes
1 answer
Template Alias with Default Value
Info
I am trying to use a template alias to improve the readabilty of my code. Ideally I would like to the alias to have a default argument such that if I leave out the template it uses the default (exactly with template functions and template…

Dan
- 12,857
- 7
- 40
- 57