parameter-pack

Recursively unpacking a template pack for a parameter-less function

纵然是瞬间 提交于 2021-01-29 13:36:09
问题 I'm trying to create a struct template with a variadic template type pack, that can deduct the sum of the size of all types passed in. Below you find a simplified example, in the real-world context, the size computed is used to create further member objects. template <typename... Types> struct OverallSize { template <typename FirstType, typename... NextTypes> static constexpr size_t sizesum() { return sizeof (FirstType) + sizesum<NextTypes...>(); } template <typename LastType> static

Divorce a parameter pack in a class template

大憨熊 提交于 2020-07-15 06:11:56
问题 I am trying to write a class template that uses a parameter-pack and implements a member function for each type contained in the parameter-pack. This is what I have so far: template <typename...T> class Myclass { public: void doSomething((Some_Operator_to_divorce?) T) { /* * Do Something */ std::cout << "I did something" << std::endl; } }; My goal is to have a class template that can be used in the following way: Myclass<std::string, int, double> M; M.doSomething("I am a String"); M

Divorce a parameter pack in a class template

梦想与她 提交于 2020-07-15 06:11:27
问题 I am trying to write a class template that uses a parameter-pack and implements a member function for each type contained in the parameter-pack. This is what I have so far: template <typename...T> class Myclass { public: void doSomething((Some_Operator_to_divorce?) T) { /* * Do Something */ std::cout << "I did something" << std::endl; } }; My goal is to have a class template that can be used in the following way: Myclass<std::string, int, double> M; M.doSomething("I am a String"); M