Questions tagged [template-aliases]

67 questions
6
votes
2 answers

Using boost::shared_ptr with a view to replacing it later

I am working on cross-platform code that needs shared pointers. For reasons beyond my control we cannot use C++11 just yet. So, I have suggested using boost::shared_ptr. When we do adopt C++11 (maybe a year down the line), we should be able to…
341008
  • 9,862
  • 11
  • 52
  • 84
5
votes
2 answers

C++ 11 conditional template alias to function

In C++ 11, I want to make a template alias with two specializations that resolve to a different function each. void functionA(); void functionB(); template using Loc_snprintf = functionA; template<> using Loc_snprintf =…
Adrián
  • 45
  • 1
  • 3
  • 12
5
votes
1 answer

Why can't GCC compiler deduce one of the template parameter from std::array in alias template form

In C++20, alias templates can have implicit deduction guides if it is applied. Then, I have constructed a simple template alias which is ints: template using ints = std::array; but: ints{1, 2, 3, 4} doesn't work, and GCC…
Desmond Gold
  • 1,517
  • 1
  • 7
  • 19
5
votes
1 answer

Strange behaviour of is_same_template on template aliases

The following program... #include #include template struct Template{}; template using Alias = Template; template < template class T1, template…
Constructor
  • 7,273
  • 2
  • 24
  • 66
5
votes
1 answer

Can type to value meta-function be used as variable alias in C++14?

While looking at C++14 the meta-function alias proposals (TransformationTraits Redux, v2,N3655), I noticed that, not only type to type transformations (such as add_const), type to value meta-functions (such as is_void ) are also type aliased. (Which…
abir
  • 1,797
  • 14
  • 26
4
votes
3 answers

Why a template alias specialization depends on the context in which it is referred?

Consider this example code: template using pt_type = typename T::type; template class V { using type = int; public: using pt = pt_type; }; void g() { V::pt a; // Does compile pt_type> b; // Does not…
Oliv
  • 17,610
  • 1
  • 29
  • 72
4
votes
0 answers

Is templated alias conducting inner and outer parameter packs non-deduced context?

The problem came from here - I wanted to create an approach solving a little bit more general problem. Consider an example: #include template using deduced = T; template
W.F.
  • 13,888
  • 2
  • 34
  • 81
4
votes
3 answers

Best way (Or workaround) to specialize a template alias

I'm currently implementing a tiny metaprogramming-based compile-time computations library. If have defined a base class for operators, which has a result typedef (I have decided to use integral wrappers like std::integral_constant as values instead…
4
votes
1 answer

Template alias not working in argument of template class template method

When I declare a template method of a template class whose argument type is specified by a template alias, I get a compile error. If I change the template class to a class, it compiles. If I replace the template alias by the actual type (here…
user2360448
  • 63
  • 2
  • 5
3
votes
1 answer

Template aliases don't work

I'm trying to get template aliases to work on clang but it doesn't work although the reference sheet says it does ~~~~>$ cat template_alias.cpp #include using namespace std; template using DoubleVec = vector>; int…
Daniel
  • 30,896
  • 18
  • 85
  • 139
3
votes
0 answers

Alias to dependent type only allows class types on GCC 12, but allows fundamental types on most other compilers

I found that the code snippet below compiles fine on gcc 11, clang, and MSVC, but starting with gcc 12.1, it gives the error: using Y = typename Derived::template X<1>; // offending line error: 'class Derived::X<1>' resolves to…
gchen
  • 126
  • 6
3
votes
2 answers

How to create alias for template type?

I have some template classes whose declaration looks like this: template class foo1; template class foo2; ... I use them in the following context…
Igor
  • 1,307
  • 1
  • 10
  • 19
3
votes
2 answers

template alias for function with varying number of arguments

I have a class template Foo which has several members, one of which is a function bar of type Bar: template class Foo { ... Bar bar; ... }; I would like Bar<2> to be a template alias for a function double (* )(double,…
JorenV
  • 373
  • 2
  • 10
3
votes
2 answers

Template alias scope

As per http://en.cppreference.com/w/cpp/language/type_alias, aliases are block-level declarations. It doesn't say anything special about template aliases, so it should be read that template aliases are block-level declarations as well. However, it…
SergeyA
  • 61,605
  • 5
  • 78
  • 137
3
votes
1 answer

C++ dynamic downcasting to class template having template template parameter being a class template or an alias template

I hope the title makes sense. I probably miss vocabulary to express it correctly. Well, an exemple will probably be more clear. Problem for me is: dynamic downcasting returns 0 at run time in some of the following cases (written in comments). I'd…
brahmin
  • 568
  • 1
  • 5
  • 17