non-type

Template template non-type parameter

删除回忆录丶 提交于 2021-01-28 18:20:58
问题 I am not really sure if there's such a feature in C++, and if there is I can't seem to make it work, so I decided to ask. Can I have a template template non-type parameter. Something like this: template<template<int> class A, int num> class C { private: A<num> obj; }; My main issue is that I want to have a class C that accepts 2 classes as template parameters. Both of these classes specialize over a non-type parameter - say A<5>, B<5> and I want to pass them to class C which accepts two

Template template non-type parameter

℡╲_俬逩灬. 提交于 2021-01-28 18:03:32
问题 I am not really sure if there's such a feature in C++, and if there is I can't seem to make it work, so I decided to ask. Can I have a template template non-type parameter. Something like this: template<template<int> class A, int num> class C { private: A<num> obj; }; My main issue is that I want to have a class C that accepts 2 classes as template parameters. Both of these classes specialize over a non-type parameter - say A<5>, B<5> and I want to pass them to class C which accepts two

Why are non-type template arguments used? [duplicate]

偶尔善良 提交于 2020-08-02 07:58:06
问题 This question already has answers here : Why we use non-type template arguments? (4 answers) Closed 3 years ago . I have read many questions and answers, but this question caught my eye the most; it and its answers are helpful but I still feel that I do not fully understand the uses and the theories behind using non-type template arguments. They provide many useful examples as to when it is used, but none really shed light on the theories behind the non-type template arguments. I am

Why are non-type template arguments used? [duplicate]

自作多情 提交于 2020-08-02 07:57:59
问题 This question already has answers here : Why we use non-type template arguments? (4 answers) Closed 3 years ago . I have read many questions and answers, but this question caught my eye the most; it and its answers are helpful but I still feel that I do not fully understand the uses and the theories behind using non-type template arguments. They provide many useful examples as to when it is used, but none really shed light on the theories behind the non-type template arguments. I am

Can lambdas be used as non-type template parameter?

…衆ロ難τιáo~ 提交于 2020-07-17 11:14:41
问题 Is the following code legal? template <auto Lambda> struct A {}; int main () { auto lmb = [](int i){return i*i;}; A<lmb> a; return 0; } I noticed that g++ compiles it fine, while clang++ returns error: a non-type template parameter cannot have type '(lambda at main.cpp:...)' . 回答1: Can lambdas be used as non-type template parameter? Yes, with implementations that has implemented P0732R2 - Class types in non-type template parameters but clang++ has not implemented it yet. Source: https://en

Can lambdas be used as non-type template parameter?

荒凉一梦 提交于 2020-07-17 11:14:19
问题 Is the following code legal? template <auto Lambda> struct A {}; int main () { auto lmb = [](int i){return i*i;}; A<lmb> a; return 0; } I noticed that g++ compiles it fine, while clang++ returns error: a non-type template parameter cannot have type '(lambda at main.cpp:...)' . 回答1: Can lambdas be used as non-type template parameter? Yes, with implementations that has implemented P0732R2 - Class types in non-type template parameters but clang++ has not implemented it yet. Source: https://en

How do I “expand” a compile-time std::array into a parameter pack?

好久不见. 提交于 2020-03-22 08:09:39
问题 I'd like to use partial template specialization in order to 'break down' an array (which is created at compile time) into a parameter pack composed of its values (to interface with other structures I define in my code). The following (my first attempt) is not compiling #include <array> template <typename T, auto k> struct K; template <typename T, std::size_t... A> struct K<T, std::array<std::size_t, sizeof...(A)>{A...}> {}; because the template argument std::array<long unsigned int, sizeof...

How do I “expand” a compile-time std::array into a parameter pack?

只愿长相守 提交于 2020-03-22 08:08:44
问题 I'd like to use partial template specialization in order to 'break down' an array (which is created at compile time) into a parameter pack composed of its values (to interface with other structures I define in my code). The following (my first attempt) is not compiling #include <array> template <typename T, auto k> struct K; template <typename T, std::size_t... A> struct K<T, std::array<std::size_t, sizeof...(A)>{A...}> {}; because the template argument std::array<long unsigned int, sizeof...