template-aliases

Strange behaviour of is_same_template on template aliases

岁酱吖の 提交于 2019-12-30 06:47:09
问题 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 <<

Variadic template aliases as template arguments

匆匆过客 提交于 2019-12-30 02:47:12
问题 First some code, then some context, then the question: template <typename T> using id = T; template <template <typename...> class F, typename... T> using apply1 = F <T...>; template <template <typename...> class F> struct apply2 { template <typename... T> using map = F <T...>; }; // ... cout << apply1 <id, int>() << endl; cout << apply2 <id>::map <int>() << endl; Both clang 3.3 and gcc 4.8.1 compile this without error, applying the identity metafunction to int , so both expressions evaluate

C++11 template alias as template template argument leads to different type?

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:40:48
问题 We have observed a strange behaviour in the compilation of the follwing source code: template<template<class> class TT> struct X { }; template<class> struct Y { }; template<class T> using Z = Y<T>; int main() { X<Y> y; X<Z> z; z = y; // it fails here } This is a slightly modified example taken from the c++11 standard proposal for template aliases: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2258.pdf (See page 4) Also note that the proposal "declares y and z to be of the same type

Alias template, partial specialization and the invalid parameter type void

不想你离开。 提交于 2019-12-12 04:10:09
问题 Consider the following code: template<typename F> struct S; template<typename Ret, typename... Args> struct S<Ret(Args...)> { }; template<typename... Args> using Alias = S<void(Args...)>; int main() { S<void(int)> s; Alias<int> alias; } It works fine, as expected and both the line involving S and the one involving Alias define under the hood the same type S<void(int)> . Now, consider the following changes: int main() { S<void(void)> s; // this line compiles Alias<void> alias; // this line

C++11 alias templates in CUDA

我怕爱的太早我们不能终老 提交于 2019-12-11 01:45:16
问题 The essential question is are alias templates supported by the CUDA compiler? I am using CUDA 7.5 on Ubuntu with gcc-4.8. All of my template classes are defined in header files and #include d into a single translation unit during compilation. I have a simple cuda_array class that provides a thin wrapper around a std::vector . It's essentially a very simple version of thrust::host_vector combined with a thrust::device_vector . Its declaration is template <typename T, const size_t N> class cuda

passing a parameter pack over a legacy function signature using forward_as_tuple

寵の児 提交于 2019-12-08 11:42:24
问题 In my app I would like to pass in a parameter pack over a legacy function signature, and change the values. Here is code that illustrates my question with my attempts as comments: #include <tuple> #include <cassert> void LegacySignature( void* param ); template< typename... ArgsT > // using ???; // attempt: can 'template alias' or 'using declaration' make the pack's type visible so I can use it inside the LegacyFunction? void MyFunc( ArgsT&... args ) { auto userArgsTuple = std::forward_as

Matching template aliases as template template parameters

落花浮王杯 提交于 2019-12-08 07:28:51
问题 I'm currently writting a metafunction to evaluate expressions, something like boost::mpl::apply: template<typename EXPRESSION , typename... ARGS> using eval = typename eval_impl<EXPRESSION,ARGS...>::result; As you can see, I'm using C++11 template aliases to avoid writting typename ::result when using the evaluator. Among other specializations, eval_impl (The implementation of the evaluation metafunction) has an specializationfor the case the user passes a parametrized expression (Such as a

Partial template binding, create new template as type

假装没事ソ 提交于 2019-12-08 02:47:43
问题 Is there some way to partially bind a template to parameter types? For example, I have the following template: template<typename T, typename Q> struct generic { }; And I have another template which takes a template class as a parameter, expecting to be able to create instances of it with the first type: template<typename T, template<typename> class Impl> struct wrapper { Impl<T> foo; }; This would accept a simple template like template<typename T> without changes. What I want to do now is

Is it possible to mark an alias template as a friend?

折月煮酒 提交于 2019-12-06 19:56:28
问题 Imagine we have this code: template <class, class> class Element {}; template <class T> class Util { public: template <class U> using BeFriend = Element<T, U>; }; Is it possible to mark BeFriend as a friend ? (Of Util , or any other class). Edit The "obvious" syntax were tried, but both failed with Clang 3.6. template <class> friend class BeFriend; template <class> friend BeFriend; I did not know about the second syntax, but found it in this answer. It seems to work (and be required) for non

What was the issue solved by the new “using” syntax for template typedefs?

我与影子孤独终老i 提交于 2019-12-06 17:23:33
问题 In C++11 you can create a "type alias" by doing something like template <typename T> using stringpair = std::pair<std::string, T>; But this is a deviation from what you'd expect a template typedef would look like: template <typename T> typedef std::pair<std::string, T> stringpair; So this raises the question - why did they need to come up with a new syntax? what was it that did not work with the old typedef syntax? I realize the last bit doesn't compile but why can't it be made to compile?