template-templates

How to transmit a template?

泄露秘密 提交于 2019-12-10 10:46:12
问题 i want a Base template class with 2 template parameters. Specially, second parameter is a template parameter. Derived is derived from Base with CRTP. Now i want to generate the base class of Derived like Base<Derived,Derived::second_tmpl> , but the generating base class isn't same as the real base class of Derived . How do i transmit a template? #include <type_traits> template<typename T, template<typename>class U> struct Base { using type = Base<T,U>; using devired_type = T; template

Template template parameter argument names usage

心已入冬 提交于 2019-12-10 00:34:54
问题 In the code template < template<class TTP> class TP > ... // whatever is TTP usable anywhere at all then? Can't find any reference to what happens with these names in the Standard. 回答1: [basic.scope.temp]/p1: The declarative region of the name of a template parameter of a template template-parameter is the smallest template-parameter-list in which the name was introduced. It can be used inside that list, and that's it. For instance, template < template<class T, T t> class TP > class foo {}; /

Build error with template template parameter only after both members are parametrized

不羁岁月 提交于 2019-12-09 13:58:05
问题 I am trying to pass a template template parameter whom its parameter is a non-type value of type equal to a subtype of a previous template parameter (whew! that was as hard to say as it is to read!), and i'm having some build errors after trying to join the results in a single parametrized templates. I have the following code (which compiles just fine with g++ 4.4.1 and -std=c++0x): #include <iostream> using namespace std; enum class Labels { A , B }; template <Labels L> struct LabelTypeMap {

How can I use `std::array` for a template parameter of the form `template<typename> class`?

↘锁芯ラ 提交于 2019-12-07 06:13:50
问题 Please consider the following tree class template<typename T, template<typename> class Tuple> class tree { private: T m_value; Tuple<tree> m_children; }; template<typename T, std::size_t N> using static_tree = tree<T, std::array<T, N>>; which is not well-defined. std::array<T, N> is not a suitable template parameter for Tuple . I assume the intend of static_tree is clear. We could do something like template<std::size_t N> struct helper { template<typename T> using type = std::array<T, N>; };

How to specialize a template with template-tempate parameters

▼魔方 西西 提交于 2019-12-07 03:57:28
问题 Edit at the end I have a function which takes a template: template <template <typename ...> class P, typename ... Args> void f(const P<Args...> &p) { std::cout << "Template with " << sizeof...(Args) << " parameters!\n"; } It works pretty good with any kind of templates I've tested so far: f(std::valarray<int>{}); // Prints: "Template with 1 parameters!" f(std::pair<char, char>{}); // Prints: "Template with 2 parameters!" f(std::set<float>{}); // Prints: "Template with 3 parameters!" f(std:

function overload matching template template

99封情书 提交于 2019-12-06 09:35:19
问题 I would expect the last two lines of the first code example to print the same. The types are deducted as I expect and the the overload resolution is also as I expect. However, if I explicitly type qualify the function call, then I get a different result then when the type is deduced. The second code example repeats the exercise replacing overload resolution with specialization. In that case everything works as anyone would expect. Any explanation? EDIT: I added one more line showing what

How to transmit a template?

本秂侑毒 提交于 2019-12-06 07:54:36
i want a Base template class with 2 template parameters. Specially, second parameter is a template parameter. Derived is derived from Base with CRTP. Now i want to generate the base class of Derived like Base<Derived,Derived::second_tmpl> , but the generating base class isn't same as the real base class of Derived . How do i transmit a template? #include <type_traits> template<typename T, template<typename>class U> struct Base { using type = Base<T,U>; using devired_type = T; template<typename V> using second_tmpl = U<V>; using second_type = second_tmpl<type>; }; template<typename T> struct

Equality of template aliases

£可爱£侵袭症+ 提交于 2019-12-05 01:23:03
I try to create template alias which cannot be distinguished from original. So, I create traits to check when 2 templates (not types) are equal: template <template <class...> class C1, template <class...> class C2> struct is_same_template : std::false_type {}; template <template <class...> class C1> struct is_same_template<C1, C1> : std::true_type {}; Now test it: // Expected alias template <typename ... Ts> using V_Ts = std::vector<Ts...>; // Variadic // Fallback alias template <typename T, typename A> using V = std::vector<T, A>; // Exact count static_assert(!is_same_template<std::vector, V

Bind metafunction: accept both types and template template parameters (accept anything)

…衆ロ難τιáo~ 提交于 2019-12-04 15:30:57
I'm trying to write a Bind metaprogramming template helper metafunction that binds a template parameter to something. I have a working implementation for simple template metafunctions: template<typename T0, typename T1> struct MakePair { using type = std::pair<T0, T1>; }; template<template<typename...> class TF, typename... Ts> struct Bind { template<typename... TArgs> using type = TF<Ts..., TArgs...>; }; using PairWithInt = typename Bind<MakePair, int>::type; static_assert(std::is_same<PairWithInt<float>, MakePair<int, float>>{}, ""); But what if MakePair 's template arguments were template

C++ variadic template template argument that matches any kind of parameters

随声附和 提交于 2019-12-04 07:43:01
问题 I was wondering if it's possible to write a template function that can take any other arbitrary template as a parameter and properly match the template name (i.e. not just the resulting class). What I know to work is this: template<template<typename ...> class TemplateT, typename... TemplateP> void f(const TemplateT<TemplateP...>& param); Which will match for instance for f(std::vector<int>()) or f(std::list<int>()) but will not work for f(std::array<int, 3>()) , as the second parameter is a