template-aliases

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

北慕城南 提交于 2021-02-04 19:00:09
问题 Consider this example code: template <class T> using pt_type = typename T::type; template <class T> class V { using type = int; public: using pt = pt_type<V>; }; void g() { V<int>::pt a; // Does compile pt_type<V<int>> b; // Does not compile } V<int>::pt is an alias for pt_type<V<int>> . Nevertheless the fact it is defined depends on the context where it is referred. Where is it explained in the C++ standard that the substitution of the template parameter by the template argument is performed

How to emulate deduction guides for template aliases?

旧时模样 提交于 2021-02-04 17:53:06
问题 Consider the following: template <typename T, std::size_t N> struct my_array { T values[N]; }; We can provide deduction guides for my_array , something like template <typename ... Ts> my_array (Ts ...) -> my_array<std::common_type_t<Ts...>, sizeof...(Ts)>; Now, suppose that my_array<T, 2> has some very special meaning (but only meaning, the interface & implementation stay the same), so that we'd like to give it a more suitable name: template <typename T> using special = my_array<T, 2>; It

C++ template alias (using) in specific places

旧街凉风 提交于 2021-01-27 04:34:29
问题 I need to use type aliases via using (or any other method) in situations like this: template <class T> typename std::enable_if< /*HERE*/>::value f (...) {}; Where I wrote HERE there are long and more than one types defined inside structures, and instead of writing typename <very long templated struct dependent on T>::type I want to write a shortcut. And I encountered this in more situations like template specializations and suffix return type syntax. So Is there any way of using using (no pun

Is a nested alias template that redeclares the same name valid?

给你一囗甜甜゛ 提交于 2021-01-07 03:11:18
问题 Given some class template: template <typename> struct T {}; a type alias declaration that changes the meaning of the name T like this is not allowed: struct S { using T = T<void>; // ill formed no diagnostic required }; There is an explanation given here as to why this is the case, and it also suggests a fix: struct S { using T = ::T<void>; // ok }; So my question is, how about an alias template as in this case? struct S { template <typename> using T = T<void>; // ok ? }; Is this well formed?

Is a nested alias template that redeclares the same name valid?

只谈情不闲聊 提交于 2021-01-07 03:10:19
问题 Given some class template: template <typename> struct T {}; a type alias declaration that changes the meaning of the name T like this is not allowed: struct S { using T = T<void>; // ill formed no diagnostic required }; There is an explanation given here as to why this is the case, and it also suggests a fix: struct S { using T = ::T<void>; // ok }; So my question is, how about an alias template as in this case? struct S { template <typename> using T = T<void>; // ok ? }; Is this well formed?

Best way (Or workaround) to specialize a template alias

爷,独闯天下 提交于 2020-01-14 13:32:12
问题 Im currently implementing a tiny metaprogramming-based compile-time computations library. If have defined a base class for operators, wich has a result typedef (I have decided to use integral wrappers like std::integral_constant as values instead of raw integral values, to provide an uniform interface along the library), and a n-ary operator base class, that checks if the operators has at least one operand: template<typename RESULT> struct operator { using result = RESULT; }; template

Best way (Or workaround) to specialize a template alias

只愿长相守 提交于 2020-01-14 13:32:06
问题 Im currently implementing a tiny metaprogramming-based compile-time computations library. If have defined a base class for operators, wich has a result typedef (I have decided to use integral wrappers like std::integral_constant as values instead of raw integral values, to provide an uniform interface along the library), and a n-ary operator base class, that checks if the operators has at least one operand: template<typename RESULT> struct operator { using result = RESULT; }; template

template template alias to a nested template?

╄→尐↘猪︶ㄣ 提交于 2020-01-13 08:12:27
问题 Template aliases are very convenient in simplifying types like typename F <T>::type to just F <T> , where T and type are types. I would like to do the same for templates like F <T>::map , i.e., simplify them to F <T> , where T and map are template structs or aliases. For instance, consider the following definitions: template <bool B> using expr = std::integral_constant <bool, B>; template <bool B> using _not = expr <!B>; template <template <typename> class F> struct neg_f { template <typename

template template alias to a nested template?

我的梦境 提交于 2020-01-13 08:11:06
问题 Template aliases are very convenient in simplifying types like typename F <T>::type to just F <T> , where T and type are types. I would like to do the same for templates like F <T>::map , i.e., simplify them to F <T> , where T and map are template structs or aliases. For instance, consider the following definitions: template <bool B> using expr = std::integral_constant <bool, B>; template <bool B> using _not = expr <!B>; template <template <typename> class F> struct neg_f { template <typename

Strange behaviour of is_same_template on template aliases

[亡魂溺海] 提交于 2019-12-30 06:48:07
问题 The following program... #include <iostream> #include <type_traits> template <typename T> struct Template{}; template <typename T> using Alias = Template<T>; template < template <typename> class T1, template <typename> class T2 > struct is_same_template : std::false_type{}; template < template <typename> class T > struct is_same_template<T, T> : std::true_type{}; int main() { std::cout << std::boolalpha; std::cout << "Template == Template: " << is_same_template<Template, Template>::value <<