template-templates

Errors while using templates templates parameters

梦想的初衷 提交于 2021-01-05 06:42:27
问题 I am studying CPP templates myself and got stuck while trying templates of templates parameters for a class. I am getting errors when I am trying to instantiate the class member. #pragma once #include "stdafx.h" # include <list> template<class type, template<type> class T> class stack { private: int count; int size; T<type> st; public: stack(size_t size):size(100), count(-1){ } void push(type elem); type pop(); }; template<class type, template<type> class T> void stack<type, T>::push(type

Errors while using templates templates parameters

让人想犯罪 __ 提交于 2021-01-05 06:39:17
问题 I am studying CPP templates myself and got stuck while trying templates of templates parameters for a class. I am getting errors when I am trying to instantiate the class member. #pragma once #include "stdafx.h" # include <list> template<class type, template<type> class T> class stack { private: int count; int size; T<type> st; public: stack(size_t size):size(100), count(-1){ } void push(type elem); type pop(); }; template<class type, template<type> class T> void stack<type, T>::push(type

Is an alias template considered equal to the “same” template? [duplicate]

瘦欲@ 提交于 2020-06-25 03:27:26
问题 This question already has answers here : Alias of a template. Who's right? (2 answers) Equality of template aliases (1 answer) Closed 2 months ago . The context This question asked if it is possible to write a trait that can retrieve the template from a given instantiation. In a nutshell the question was: "Is it possible to write a f such that f<foo<int>>::type is foo ?" This answer presents something that I would have expected to be exactly what that question asked for, but the answer

Can a variable template be passed as a template template argument?

☆樱花仙子☆ 提交于 2020-05-23 04:20:42
问题 The following nonsensical example does not compile, but is there some other way to pass a variable template as a template template argument? template<typename T> constexpr auto zero = T{0}; template<typename T, template<typename> auto VariableTemplate> constexpr auto add_one() { return VariableTemplate<T> + T{1}; } int main() { return add_one<int, zero>(); } Try on Compiler Explorer 回答1: Short answer: No. Long answer: Yes you can using some indirection through a class template: template

How do nested templates get resolved in C++?

只愿长相守 提交于 2020-03-23 05:42:22
问题 I recently asked a question about determining whether an iterator points to a complex value at compile time and received an answer that works. The question is here: How can I specialize an algorithm for iterators that point to complex values? And the solution was a set of templates that determine whether one template is a specialization of another: template <class T, template <class...> class Template> struct is_specialization : std::false_type {}; template <template <class...> class Template

How do nested templates get resolved in C++?

一世执手 提交于 2020-03-23 05:42:08
问题 I recently asked a question about determining whether an iterator points to a complex value at compile time and received an answer that works. The question is here: How can I specialize an algorithm for iterators that point to complex values? And the solution was a set of templates that determine whether one template is a specialization of another: template <class T, template <class...> class Template> struct is_specialization : std::false_type {}; template <template <class...> class Template

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

拥有回忆 提交于 2020-02-01 05:33:05
问题 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

Wrapping template template parameter class with SWIG

為{幸葍}努か 提交于 2020-01-03 10:58:15
问题 I have a C++ class like the following: template< template<typename> class ContainerType, typename MemberType> class MyClass { public: MyClass(ContainerType<MemberType>* volData); } which I am trying to wrap with SWIG. My MyClass.i looks like: %module MyClass %{ #include "SimpleContainer.h" #include "MyClass.h" %} %include "SimpleContainer.h" %include "MyClass.h" %template(MyClass_SimpleContainer_Int) MyClass<SimpleContainer, int>; However, SWIG seems to have problems with the template

Wrapping template template parameter class with SWIG

删除回忆录丶 提交于 2020-01-03 10:58:14
问题 I have a C++ class like the following: template< template<typename> class ContainerType, typename MemberType> class MyClass { public: MyClass(ContainerType<MemberType>* volData); } which I am trying to wrap with SWIG. My MyClass.i looks like: %module MyClass %{ #include "SimpleContainer.h" #include "MyClass.h" %} %include "SimpleContainer.h" %include "MyClass.h" %template(MyClass_SimpleContainer_Int) MyClass<SimpleContainer, int>; However, SWIG seems to have problems with the template

Tagging objects using enums via template-template parameters

爷,独闯天下 提交于 2019-12-25 16:53:16
问题 I would like to use an enum argument of a template, to restrict a second argument, a class, to in turn taking an member of the enum as an argument as it's templated parameter. In code, I would expect this to look like: CObject<EObjectTag, CSubObject<EObjectTag::CAT_A>> cObject; this should work, however: CObject<EObjectTag, CSubObject<ENotAnObjectTag::CAT_OTHER>> cObject; should fail as ENotAnObjectTag::CAT_OTHER is not a element of EObjectTag . My implementation (attempt) of this, is as