variadic-templates

Calling virtual method of base template from derived variadic template class

烈酒焚心 提交于 2019-12-09 09:10:49
问题 This is essentially a follow-up to an earlier question (not posed by me, but I am interested in an answer). The question is: Why does the compiler/linker fail to resolve the call to the virtual function from the derived class? In this case, the derived class is a template class with variadic parameters that applies multiple inheritance against the same template class multiple times (once for each type in the variadic parameters). In the concrete example below, the derived class is JobPlant ,

Multiple Variadic Parameter Pack for Template Class

蓝咒 提交于 2019-12-09 06:12:13
问题 I am using variadic parameter packs for policy based class design. template <APITypes APIType, class... Policies> class IShader : public Policies... { }; Policies are defined when called or with defaults if none are specified. The problem comes when I need to add another variadic parameter pack: template <AttributeType... Attributes, APITypes APIType, class... Policies> class IShader : public Policies... { }; This results in the error "Template parameter pack must be the last template

Template parameter - function pointer with variadic arguments

馋奶兔 提交于 2019-12-09 04:51:34
问题 I know I can do this: template<typename T, typename Ret, typename A1, typename A2, Ret(T::*F)(A1, A2)> class C{} But as you can see this A1 and A2 are bit ugly. In fact I don't know the number of arguments. Sounds like a work for variadic templates. Unfortunately I can't do this: // doesn't work - parameter pack must appear at the end of the template parameter list template<typename T, typename Ret, typename... Args, Ret(T::*F)(Args...)> class C{} Nor this: template class C; // doesn't work -

CUDA kernel with function pointer and variadic templates

人盡茶涼 提交于 2019-12-09 03:58:53
问题 I am trying to design a cuda framework which would accept user functions and forward them to the kernel, through device function pointers. CUDA can work with variadic templates (-stc=c++11) and so far so good. However, I hit a problem when the kernel calls the device function pointer. Apparently the kernel runs with no problem, but the GPU usage is 0%. If I simply replace the callback pointer with the actual function then GPU usage is 99%. The code here is very simple and the large loop range

Cast lambda to std::function with parameter pack

你离开我真会死。 提交于 2019-12-09 02:49:43
问题 There are several questions on SO that relate to casting lambdas to std::function s, but I have yet to see one that uses a parameter pack for the argument list. This seems broken on my version of g++ (7.1.1-4), and possibly it's just not supported. So is this legal c++17 (by the standard)? If not, why? #include <functional> template <typename TReturn, typename ... TArgs> void Functor(std::function<TReturn (TArgs...)> f) {} int main(int argc, char * argv[]) { auto x = [] (int a, int b) {

C++ parameter pack, constrained to have instances of a single type?

限于喜欢 提交于 2019-12-09 02:09:29
问题 Since C++11 we can make template functions which can accept any sequence of arguments: template <typename... Ts> void func(Ts &&... ts) { step_one(std::forward<Ts>(ts)...); step_two(std::forward<Ts>(ts)...); } However, suppose that it really only makes sense to call my function in the case where each argument has the same type -- any number of arguments would be okay though. What's the best way to do that, i.e. is there a good way to constrain the templates to make a nice error message in

Binding a generic member function

旧街凉风 提交于 2019-12-09 01:47:41
问题 Sometimes I need to bind some member functions to its calling object, to treat member functions and non-member functions in the same homogeneous way. For example (The tipical callback example): #include <vector> #include <functional> void f(int){} struct foo { void f(int){} }; int main() { using namespace std::placeholders; foo my_foo; std::vector<std::function<void()>> functions; functions.push_back( f ); functions.push_back([](int){}); functions.push_back( std::bind( &foo::f , my_foo , _1 )

Iterating variadic template arguments in reverse order

浪子不回头ぞ 提交于 2019-12-08 21:25:32
The following code is working if I manual reverse the order of the template arguments which is passed to it: template<typename HeadTag, typename... TailTag> struct Mapped_scope_deep : public Mapped_scope_deep<TailTag...> { typedef typename boost::mpl::at<typename Mapped_scope_deep<TailTag...>::type::type_map, HeadTag>::type type; }; template<typename HeadTag> struct Mapped_scope_deep<HeadTag> { typedef typename boost::mpl::at<type_map, HeadTag>::type type; }; Example: // typename Mapped_scope_deep<T0, T1, T2, T3>::type // needs to be written as typename Mapped_scope_deep<T3, T2, T1, T0>::type

How to match empty arguments pack in variadic template

不打扰是莪最后的温柔 提交于 2019-12-08 20:33:33
问题 I have code: template<typename T> void loadBrush_sub_impl() { // do some work here } template<typename T, typename... Targs> void loadBrush_sub() { loadBrush_sub_impl<T>(); loadBrush_sub<Targs...>(); } template<> void loadBrush_sub<void>() { } // BasicBrush, BinaryBrush, SketchBrush, BasicEraser and MaskBased are class loadBrush_sub<BasicBrush, BinaryBrush, SketchBrush, BasicEraser, MaskBased, void>(); This is correct when compile it. However, I really want to drop the void in the call

MSVC 2013 'type' : is not a member of 'std::enable_if<false,void>

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 19:23:19
问题 My SFINAE code using std::enable_if compiles in GCC & Clang, but not in MSVC 2013. The code (also available on cpp.sh) is #include <iostream> #include <type_traits> template <typename T, typename ... AdditionalInputs> typename std::enable_if<sizeof...(AdditionalInputs) == 0, void>::type CallDoDataProcessing(T var) { std::cout << sizeof...(AdditionalInputs) << " additional inputs" << std::endl; } template <typename T, typename ... AdditionalInputs> typename std::enable_if<sizeof...