variadic-templates

Multiple parameter packs — how?

我只是一个虾纸丫 提交于 2021-02-20 10:13:06
问题 I have the following problem: #include <vector> #include <tuple> using namespace std; template< size_t... N_i, typename Ts... > class A { // ... private: std::vector<size_t> _v = { N_i... }; std::tuple<Ts...> _t; }; int main() { A<1> a; } As you can see above, I try to define multiple parameter packs as template arguments of the class A . Unfortunately, the code does not compile: error: expected nested-name-specifier before 'Ts' How can I define multiple parameter packs for this example? 回答1:

Multiple parameter packs — how?

非 Y 不嫁゛ 提交于 2021-02-20 10:10:15
问题 I have the following problem: #include <vector> #include <tuple> using namespace std; template< size_t... N_i, typename Ts... > class A { // ... private: std::vector<size_t> _v = { N_i... }; std::tuple<Ts...> _t; }; int main() { A<1> a; } As you can see above, I try to define multiple parameter packs as template arguments of the class A . Unfortunately, the code does not compile: error: expected nested-name-specifier before 'Ts' How can I define multiple parameter packs for this example? 回答1:

Multiple parameter packs — how?

孤者浪人 提交于 2021-02-20 10:06:51
问题 I have the following problem: #include <vector> #include <tuple> using namespace std; template< size_t... N_i, typename Ts... > class A { // ... private: std::vector<size_t> _v = { N_i... }; std::tuple<Ts...> _t; }; int main() { A<1> a; } As you can see above, I try to define multiple parameter packs as template arguments of the class A . Unfortunately, the code does not compile: error: expected nested-name-specifier before 'Ts' How can I define multiple parameter packs for this example? 回答1:

Multiple parameter packs — how?

穿精又带淫゛_ 提交于 2021-02-20 10:06:23
问题 I have the following problem: #include <vector> #include <tuple> using namespace std; template< size_t... N_i, typename Ts... > class A { // ... private: std::vector<size_t> _v = { N_i... }; std::tuple<Ts...> _t; }; int main() { A<1> a; } As you can see above, I try to define multiple parameter packs as template arguments of the class A . Unfortunately, the code does not compile: error: expected nested-name-specifier before 'Ts' How can I define multiple parameter packs for this example? 回答1:

How does using ellipses for SFINAE work?

空扰寡人 提交于 2021-02-20 08:59:25
问题 When using SFINAE to select constructor overloads in the past, I have typically used the following: template <typename T> class Class { public: template <typename U = T, typename std::enable_if<std::is_void<U>::value, int>::type=0> Class() { std::cout << "void" << std::endl; } template <typename U = T, typename std::enable_if<!std::is_void<U>::value, int>::type=0> Class() { std::cout << "not void" << std::endl; } }; However, I just came across this alternative: template <typename U = T,

How to create a tuple of vectors of type deduced from a variadic template in C++17?

▼魔方 西西 提交于 2021-02-19 05:04:11
问题 I have implemented a collection class that converts a vector of tuples to a tuple of vectors (it is essentially an AOS to SOA conversion). This code works for this example of two template classes. I was trying to make it more generic by using variadic templates. In order to do that I need to create the type for the member variable m_col . In C++17, is it possible to convert a tuple to a tuple of vectors? So the type of the member variance m_col in this example will be generated automatically

How to remove last argument of variadic template

北城余情 提交于 2021-02-19 02:28:06
问题 I have following structure, I want remove last argument from index_sequence : template< std::size_t ... values> struct index_sequence{}; // I need something like template< typename IndexSequence> struct pop_back; template< std::size_t ... values > struct pop_back< index_sequence< values... > > { typedef index_sequence< /** values except last one*/ > type; }; How to implement this pop_back structure? I know implementation, only it requires deep recursion, I want without deep recursion

Variadic template resolution in VS2013 - Error C3520

孤街浪徒 提交于 2021-02-17 00:07:24
问题 What's wrong with this code? enum LogLevel { LogLevel_Error = 1, LogLevel_Warning = 2, LogLevel_Info = 3, LogLevel_Debug = 4 }; LogLevel GetLogLevel() {return LogLevel_Debug;}; void Write(const std::string& message) {}; void Write(LogLevel level, std::stringstream& ss) { if (level > GetLogLevel()) return; Write(ss.str()); } template<typename Arg> void Write(LogLevel level, std::stringstream& ss, Arg arg) { if (level > GetLogLevel()) return; ss << arg; Write(ss.str()); } template<typename

Variadic template resolution in VS2013 - Error C3520

淺唱寂寞╮ 提交于 2021-02-17 00:06:30
问题 What's wrong with this code? enum LogLevel { LogLevel_Error = 1, LogLevel_Warning = 2, LogLevel_Info = 3, LogLevel_Debug = 4 }; LogLevel GetLogLevel() {return LogLevel_Debug;}; void Write(const std::string& message) {}; void Write(LogLevel level, std::stringstream& ss) { if (level > GetLogLevel()) return; Write(ss.str()); } template<typename Arg> void Write(LogLevel level, std::stringstream& ss, Arg arg) { if (level > GetLogLevel()) return; ss << arg; Write(ss.str()); } template<typename

Explicit template instantiation with variadic templates

£可爱£侵袭症+ 提交于 2021-02-16 04:48:39
问题 I have several template classes Impl (with some abstract methods) that are partially implemented in CPP files so that I need to explicitly instantiate my templates for the linker to find it, like this: template class Impl<T0>; template class Impl<T1>; template class Impl<T2>; ... template class Impl<Tx>; As the number of types Tx grows, I would like to find a better way than to manually expand these lists of explicit instantiations in all necessary files. I thought I could use variadic