template-templates

Help with c++ template templates

别等时光非礼了梦想. 提交于 2019-12-24 00:26:09
问题 Ok, so I wrote an stl-like algorithm called cartesian_product . For those who don't know, the cartesian product is every possible pair of elements from two sets. So the cartesian product of {1, 2, 3} and {10, 20, 30} is {(1,10), (1,20), (1,30), (2,10), (2,20), (2,30), (3,10), (3,20), (3,30)} So the function looks like template <typename InIt1, typename InIt2, typename OutIt> void cartesian_product(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2, OutIt out) { for (; first1 != last1; +

Throw multiple-template class in a template template parameter - template binding?

别来无恙 提交于 2019-12-23 12:51:10
问题 Given the following class: template <class T, template <typename> class B> class A { B<T> b; }; I can now write code like such: A<float, MyVector> a1; A<int, MySet> a2; What is the most elegant way to put multi-parameter classes of which all parameters are specified except one, in B? Like a map with int-keys? The only thing I can come up with is this: template <class U> using C = MyMap<int, U>; A<float, C<int>> a3; Is there such a template equivalent to std::bind, where we can provide only a

Template function overload for type containing a type

妖精的绣舞 提交于 2019-12-22 05:33:08
问题 I'm trying to do the following: #include <iostream> #include <vector> #include <tuple> #include <list> template <typename T> void f(T t) { std::cout << "1" << std::endl; } template <typename T, typename V> void f(T<std::tuple<V>> t) { std::cout << "2" << std::endl; } int main() { f(std::list<double>{}); // should use first template f(std::vector<std::tuple<int>>{}); // should use second template } What is the simplest way to do this in C++14? I thought that I could sort of pattern match in

Equality of template aliases

家住魔仙堡 提交于 2019-12-22 04:10:11
问题 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,

Use std::tuple for template parameter list instead of list of types

爷,独闯天下 提交于 2019-12-19 09:02:31
问题 I'm trying to make a call to a templated function like this : typedef std::tuple<int, double, bool> InstrumentTuple; Cache cache; InstrumentTuple tuple = cache.get<InstrumentTuple>(); I know I could "simply" pass the types of the tuple. This is what I do know but it is quite cumbersome since I make a lot of calls to this function and since the tuples are quite long: InstrumentTuple tuple = c.get<int, double, bool>(); // syntax I'd like to avoid So I tried multiple implementations of the get

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

Variadic template templates and perfect forwarding

◇◆丶佛笑我妖孽 提交于 2019-12-17 21:45:53
问题 This question on the object generator pattern got me thinking about ways to automate it. Essentially, I want to automate the creation of functions like std::make_pair , std::bind1st and std::mem_fun so that instead of having to write a different function for each template class type, you could write a single variadic template template function that handles all cases at once. Usage of this function would be like: make<std::pair>(1, 2); // equivalent to std::make_pair(1, 2) make<std::binder2nd>

use the signature of a generic function dependent on a non-type template argument as template template argument

故事扮演 提交于 2019-12-11 00:34:54
问题 The small program below, which compiles and runs, allows to bridge a runtime variable index of type unsigned with a set of template functions having one template argument J of type unsigned . In case further clarifications are needed, this is better explained in this question. The auxiliary functions I wrote use a template template argument, to infer as much info as possible from the original function. The problem is that I could not find a better way to define the template template argument

Error overloading function with different template template parameters with same argument

我怕爱的太早我们不能终老 提交于 2019-12-10 21:05:40
问题 I have a class that gets two template template parameters and overloads a function with an argument that is either the one or the other template template parameter but both times with the same template argument: template<template<typename> class TemplArgA, template<typename> class TemplArgB> class CompileError { public: void func(TemplArgA<int> x) {} void func(TemplArgB<int> x) {} }; I am using VC2010 and get error C2535: 'void CompileError<TemplArgA,TemplArgB>::func(TemplArgA<int>)': member

Vector of pairs with generic vector and pair type, template of template

戏子无情 提交于 2019-12-10 18:56:36
问题 I'd like to pass a vector of pairs to a function. The actual vector implementation as well as the types of the pair should be a template parameter. I thought of something like this: template<uint8_t t_k, typename t_bv, typename t_rank, template <template <template<typename t_x, typename t_y> class std::pair> typename t_vector>> typename t_vector> The first 3 are other template parameters. The last template parameter should allow to pass a vector ( std or stxxl:vector ) of std::pair with