Questions tagged [template-aliases]
67 questions
50
votes
2 answers
Pack expansion for alias template
It seems that a pack argument can be expanded only in the place of a pack parameter of an alias template. This is not true for a class or a function template:
template struct x { using type = T; };
template

bolov
- 72,283
- 15
- 145
- 224
41
votes
1 answer
Why does alias template give a conflicting declaration?
The port of some C++11 code from Clang to g++
template
using value_t = typename T::value_type;
template
struct S
{
using value_type = int;
static value_type const C = 0;
};
template
value_t> // gcc error,…

TemplateRex
- 69,038
- 19
- 164
- 304
39
votes
2 answers
Can I use template aliases as template template parameters?
Can I use template aliases as template template parameters?
template class> struct foo {};
template using simple_ptr = std::unique_ptr;
foo a; // this doesn't work, std::unique_ptr has two…

R. Martinho Fernandes
- 228,013
- 71
- 433
- 510
17
votes
1 answer
Variadic template aliases as template arguments
First some code, then some context, then the question:
template using id = T;
template class F, typename... T>
using apply1 = F ;
template class F>
struct apply2
{
template…

iavr
- 7,547
- 1
- 18
- 53
16
votes
1 answer
Explicitly instantiate class through template alias
Is it possible to explicitly instantiate a template class through a template alias?
If so, how? Otherwise, can someone point to the ISO paper in which this was discussed and decided against?
template
struct A { };
/// Explicit instantiate…

gnzlbg
- 7,135
- 5
- 53
- 106
16
votes
4 answers
What was the issue solved by the new "using" syntax for template typedefs?
In C++11 you can create a "type alias" by doing something like
template
using stringpair = std::pair;
But this is a deviation from what you'd expect a template typedef would look like:
template
typedef…

shoosh
- 76,898
- 55
- 205
- 325
15
votes
1 answer
Unpacking parameter packs in template aliases
I run into a problem with unpacking variadic templates into a template alias.
The following code works with Clang 3.4 and GCC 4.8 but fails with GCC 4.9:
template
using front_type = T;
template
struct…

mavam
- 12,242
- 10
- 53
- 87
14
votes
3 answers
Can I specialize a class template with an alias template?
Here's a simple example:
class bar {};
template
class foo {};
template <>
using foo = bar;
Is this allowed?

R. Martinho Fernandes
- 228,013
- 71
- 433
- 510
14
votes
3 answers
g++ Bug with Partial Template Specialization
I am writing some TMP-heavy code for g++ (version 4.8.1_1, Macports) and clang++ (version 3.3, Macports). While g++ rejects the following code listing with UNBRIDLED FURY, clang++ compiles it with grace and splendor.
Which complier is in the right?…

void-pointer
- 14,247
- 11
- 43
- 61
13
votes
3 answers
How do template aliases affect template parameter deduction?
In C++03, template parameter deduction does not occur in some contexts. For example:
template struct B {};
template
struct A
{
typedef B type;
};
template
void f(typename A::type);
int main()
{
…

HighCommander4
- 50,428
- 24
- 122
- 194
13
votes
2 answers
Is it possible to mark an alias template as a friend?
Imagine we have this code:
template
class Element
{};
template
class Util
{
public:
template
using BeFriend = Element;
};
Is it possible to mark BeFriend as a friend ? (Of Util, or any other…

Ad N
- 7,930
- 6
- 36
- 80
13
votes
2 answers
Variadic template aliases as template arguments (part 2)
This is a follow-up of another question. It refers to the same problem (I hope) but uses an entirely different example to illustrate it. The reason is that in the previous example only experimental GCC 4.9 failed with a compiler error. In this…

iavr
- 7,547
- 1
- 18
- 53
12
votes
1 answer
How to write deduction guidelines for aliases of aggregate templates?
With C++20, it is possible to have deduction guidelines generated for an alias template (See section "Deduction for alias templates" at https://en.cppreference.com/w/cpp/language/class_template_argument_deduction). Yet, I could not make them work…

Arjonais
- 563
- 2
- 17
12
votes
1 answer
Template alias visibility in nested class
Consider the following:
template
struct Z {};
struct A
{
using Z = ::Z;
struct B : Z
{
using C = Z;
};
};
This compiles fine. Nice. But now add another parameter in Z:
template

iavr
- 7,547
- 1
- 18
- 53
12
votes
1 answer
template aliases and sfinae
In the case of a substitution failure involving a template alias (e.g. a template alias on a missing member typename, as in the code snippet below), should an error be triggered ?
Clang and gcc seem to disagree on this:
// some types
struct bar {…

max
- 1,048
- 10
- 20