c++14

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:

gcc doesn't accept out-of-line definition of member with non-type template parameter defined via nested templated using clause

戏子无情 提交于 2021-02-19 04:07:51
问题 The title seems convoluted but our test-case is actually a minimal example for a real case. We have code for which we want to choose implementation of a method based on the template parameter. We during clean up we defined conditional enable_if_t with using clause, and as next step wanted to put definition out of line, this produced following code: #include <type_traits> #include <iostream> #include <string> template <typename T> struct A { template <typename U> using is_int_or_float = std:

gcc doesn't accept out-of-line definition of member with non-type template parameter defined via nested templated using clause

混江龙づ霸主 提交于 2021-02-19 04:07:34
问题 The title seems convoluted but our test-case is actually a minimal example for a real case. We have code for which we want to choose implementation of a method based on the template parameter. We during clean up we defined conditional enable_if_t with using clause, and as next step wanted to put definition out of line, this produced following code: #include <type_traits> #include <iostream> #include <string> template <typename T> struct A { template <typename U> using is_int_or_float = std:

How do I declare a vector of vector::size_type?

折月煮酒 提交于 2021-02-19 03:52:07
问题 I want a vector whose elements are of the type vector::size_type However, you cannot declare: vector<vector::size_type> aVec; because size_type is part of the template itself, so you have to use the type itself, I need something like: vector<vector<T>::size_type> aVec; but what should the T be? It's really a circular problem. :) If vector had just used size_t as its size type (but not had a special typedef for the size_type which could vary maybe based on the type that the vector is holding),

How do I declare a vector of vector::size_type?

◇◆丶佛笑我妖孽 提交于 2021-02-19 03:52:05
问题 I want a vector whose elements are of the type vector::size_type However, you cannot declare: vector<vector::size_type> aVec; because size_type is part of the template itself, so you have to use the type itself, I need something like: vector<vector<T>::size_type> aVec; but what should the T be? It's really a circular problem. :) If vector had just used size_t as its size type (but not had a special typedef for the size_type which could vary maybe based on the type that the vector is holding),

Compile-time template `std::integral_constant` counter - how to implement it?

守給你的承諾、 提交于 2021-02-18 23:00:47
问题 I have several types and I want to "bind" an std::integral_constant sequential ID value to every type at compile-time. Example: struct Type00 { }; struct Type01 { }; struct Type02 { }; struct Type03 { }; struct TypeXX { }; struct TypeYY { }; template<typename T> struct TypeInfo { using Id = std::integral_constant<int, ???>; }; int main() { cout << TypeInfo<Type00>::Id::value; // Should always print 0 cout << TypeInfo<Type01>::Id::value; // Should always print 1 cout << TypeInfo<Type02>::Id:

How to generate nested loops at compile time

亡梦爱人 提交于 2021-02-17 09:14:37
问题 I have an integer N which I know at compile time. I also have an std::array holding integers describing the shape of an N -dimensional array. I want to generate nested loops, as described bellow, at compile time, using metaprogramming techniques. constexpr int N {4}; constexpr std::array<int, N> shape {{1,3,5,2}}; auto f = [/* accept object which uses coords */] (auto... coords) { // do sth with coords }; // This is what I want to generate. for(int i = 0; i < shape[0]; i++) { for(int j = 0; j