Check if class is a template specializationC++ variadic template template argument that matches any kind of parametersCheck if class is a template specialization?c++ auto for type and nontype templatesCheck if two types are of the same templateStoring C++ template function definitions in a .CPP fileWhy can templates only be implemented in the header file?Template specialization with struct and boolC++ specialization of template function inside template classPartial specialization of variadic templatesHow to prevent specialization of std::vector<bool>Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsHow to specialize template template parameter for std::vector in C++Define partial specialization for some external template classes with restriction for template parametersHow to specialize for template template arguments
Statistical tests for benchmark comparison
Why are some files not movable on Windows 10?
Unable to find solution to 6 simultaneous equations
Why does Kubuntu 19.04 show an update that apparently doesn't exist?
Can an infinite series be thought of as adding up "infinitely many" terms?
Does a feasible high thrust high specific impulse engine exist using current non space technology?
Planar regular languages
How to create an animated flowchart with LaTeX?
Teleport everything in a large zone; or teleport all living things and make a lot of equipment disappear
How to make classical firearms effective on space habitats despite the coriolis effect?
Shouldn't countries like Russia and Canada support global warming?
Is it appropriate to CC a lot of people on an email
What organs or modifications would be needed for a life biological creature not to require sleep?
Test to know when to use GLM over Linear Regression?
What's the benefit of prohibiting the use of techniques/language constructs that have not been taught?
Permutations in Disguise
Expectation value of operators with non-zero Hamiltonian commutators
How do certain apps show new notifications when internet access is restricted to them?
Can Brexit be undone in an emergency?
In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?
What is this gigantic dish at Ben Gurion airport?
Impossible Scrabble Words
Amortized Loans seem to benefit the bank more than the customer
Why any infinite sequence of real functions can be generated from a finite set through composition?
Check if class is a template specialization
C++ variadic template template argument that matches any kind of parametersCheck if class is a template specialization?c++ auto for type and nontype templatesCheck if two types are of the same templateStoring C++ template function definitions in a .CPP fileWhy can templates only be implemented in the header file?Template specialization with struct and boolC++ specialization of template function inside template classPartial specialization of variadic templatesHow to prevent specialization of std::vector<bool>Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsHow to specialize template template parameter for std::vector in C++Define partial specialization for some external template classes with restriction for template parametersHow to specialize for template template arguments
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to check if a class is a template specialization of another one. What I have tried is:
template <class T, template <class...> class Template>
struct is_specialization : std::false_type ;
template <template <class...> class Template, class... Args>
struct is_specialization<Template<Args...>, Template> : std::true_type ;
It works fine when all template parameters are type arguments but not when some are non-type arguments. For example it works with std::vector
but not std::array
(since the later accepts an non-type argument std::size_t
).
It's important that the check is made at compile time. Also the solution must work for any template, not just vectors or arrays. That means that it can be any number of type arguments and any number of non-type arguments. For example it should work with template <class A, bool B, class C, int D, class... Args> class foo;
c++
|
show 4 more comments
I want to check if a class is a template specialization of another one. What I have tried is:
template <class T, template <class...> class Template>
struct is_specialization : std::false_type ;
template <template <class...> class Template, class... Args>
struct is_specialization<Template<Args...>, Template> : std::true_type ;
It works fine when all template parameters are type arguments but not when some are non-type arguments. For example it works with std::vector
but not std::array
(since the later accepts an non-type argument std::size_t
).
It's important that the check is made at compile time. Also the solution must work for any template, not just vectors or arrays. That means that it can be any number of type arguments and any number of non-type arguments. For example it should work with template <class A, bool B, class C, int D, class... Args> class foo;
c++
I'm afraid what you want is not possible: stackoverflow.com/q/25893828/5470596
– YSC
Mar 28 at 11:56
1
Catching bothstd::vector
andstd::array
can easily be done by adding anauto...
pack, but that would still only work if all type parameters comes first, and the non-types comes after. Catching a mixed pattern is AFAIK not possible.
– super
Mar 28 at 12:01
@YSC That post is old, in C++17 new features such asauto
for non-type parameter deduction were introduced, now maybe is possible. I haven't been able to find a way though.
– user28032019
Mar 28 at 12:02
1
I think C++ compilers really really hate mixing types and values (hello most vexing parse) and tries to stay as far away as possible. Or in other words, this is impossible. Or @Quentin manages to abuse the most vexing parse again and wraps everything into one magnificent macro.
– Passer By
Mar 28 at 12:58
1
@PasserBy I'm sorry to disappoint, but the parser went through unscathed this time.
– Quentin
Mar 28 at 13:22
|
show 4 more comments
I want to check if a class is a template specialization of another one. What I have tried is:
template <class T, template <class...> class Template>
struct is_specialization : std::false_type ;
template <template <class...> class Template, class... Args>
struct is_specialization<Template<Args...>, Template> : std::true_type ;
It works fine when all template parameters are type arguments but not when some are non-type arguments. For example it works with std::vector
but not std::array
(since the later accepts an non-type argument std::size_t
).
It's important that the check is made at compile time. Also the solution must work for any template, not just vectors or arrays. That means that it can be any number of type arguments and any number of non-type arguments. For example it should work with template <class A, bool B, class C, int D, class... Args> class foo;
c++
I want to check if a class is a template specialization of another one. What I have tried is:
template <class T, template <class...> class Template>
struct is_specialization : std::false_type ;
template <template <class...> class Template, class... Args>
struct is_specialization<Template<Args...>, Template> : std::true_type ;
It works fine when all template parameters are type arguments but not when some are non-type arguments. For example it works with std::vector
but not std::array
(since the later accepts an non-type argument std::size_t
).
It's important that the check is made at compile time. Also the solution must work for any template, not just vectors or arrays. That means that it can be any number of type arguments and any number of non-type arguments. For example it should work with template <class A, bool B, class C, int D, class... Args> class foo;
c++
c++
edited Mar 28 at 11:48
YSC
28k6 gold badges60 silver badges115 bronze badges
28k6 gold badges60 silver badges115 bronze badges
asked Mar 28 at 11:44
user28032019user28032019
555 bronze badges
555 bronze badges
I'm afraid what you want is not possible: stackoverflow.com/q/25893828/5470596
– YSC
Mar 28 at 11:56
1
Catching bothstd::vector
andstd::array
can easily be done by adding anauto...
pack, but that would still only work if all type parameters comes first, and the non-types comes after. Catching a mixed pattern is AFAIK not possible.
– super
Mar 28 at 12:01
@YSC That post is old, in C++17 new features such asauto
for non-type parameter deduction were introduced, now maybe is possible. I haven't been able to find a way though.
– user28032019
Mar 28 at 12:02
1
I think C++ compilers really really hate mixing types and values (hello most vexing parse) and tries to stay as far away as possible. Or in other words, this is impossible. Or @Quentin manages to abuse the most vexing parse again and wraps everything into one magnificent macro.
– Passer By
Mar 28 at 12:58
1
@PasserBy I'm sorry to disappoint, but the parser went through unscathed this time.
– Quentin
Mar 28 at 13:22
|
show 4 more comments
I'm afraid what you want is not possible: stackoverflow.com/q/25893828/5470596
– YSC
Mar 28 at 11:56
1
Catching bothstd::vector
andstd::array
can easily be done by adding anauto...
pack, but that would still only work if all type parameters comes first, and the non-types comes after. Catching a mixed pattern is AFAIK not possible.
– super
Mar 28 at 12:01
@YSC That post is old, in C++17 new features such asauto
for non-type parameter deduction were introduced, now maybe is possible. I haven't been able to find a way though.
– user28032019
Mar 28 at 12:02
1
I think C++ compilers really really hate mixing types and values (hello most vexing parse) and tries to stay as far away as possible. Or in other words, this is impossible. Or @Quentin manages to abuse the most vexing parse again and wraps everything into one magnificent macro.
– Passer By
Mar 28 at 12:58
1
@PasserBy I'm sorry to disappoint, but the parser went through unscathed this time.
– Quentin
Mar 28 at 13:22
I'm afraid what you want is not possible: stackoverflow.com/q/25893828/5470596
– YSC
Mar 28 at 11:56
I'm afraid what you want is not possible: stackoverflow.com/q/25893828/5470596
– YSC
Mar 28 at 11:56
1
1
Catching both
std::vector
and std::array
can easily be done by adding an auto...
pack, but that would still only work if all type parameters comes first, and the non-types comes after. Catching a mixed pattern is AFAIK not possible.– super
Mar 28 at 12:01
Catching both
std::vector
and std::array
can easily be done by adding an auto...
pack, but that would still only work if all type parameters comes first, and the non-types comes after. Catching a mixed pattern is AFAIK not possible.– super
Mar 28 at 12:01
@YSC That post is old, in C++17 new features such as
auto
for non-type parameter deduction were introduced, now maybe is possible. I haven't been able to find a way though.– user28032019
Mar 28 at 12:02
@YSC That post is old, in C++17 new features such as
auto
for non-type parameter deduction were introduced, now maybe is possible. I haven't been able to find a way though.– user28032019
Mar 28 at 12:02
1
1
I think C++ compilers really really hate mixing types and values (hello most vexing parse) and tries to stay as far away as possible. Or in other words, this is impossible. Or @Quentin manages to abuse the most vexing parse again and wraps everything into one magnificent macro.
– Passer By
Mar 28 at 12:58
I think C++ compilers really really hate mixing types and values (hello most vexing parse) and tries to stay as far away as possible. Or in other words, this is impossible. Or @Quentin manages to abuse the most vexing parse again and wraps everything into one magnificent macro.
– Passer By
Mar 28 at 12:58
1
1
@PasserBy I'm sorry to disappoint, but the parser went through unscathed this time.
– Quentin
Mar 28 at 13:22
@PasserBy I'm sorry to disappoint, but the parser went through unscathed this time.
– Quentin
Mar 28 at 13:22
|
show 4 more comments
1 Answer
1
active
oldest
votes
C++20 is a weird, weird world. Cross-checking is welcome as I'm a beginner with CTAD and not entirely sure I've covered all bases.
This solution uses SFINAE to check whether class template argument deduction (CTAD) succeeds between the requested class template and the mystery type. An additional is_same
check is performed to prevent against unwanted conversions.
template <auto f>
struct is_specialization_of
private:
template <class T>
static auto value_impl(int) -> std::is_same<T, decltype(f.template operator()<T>())>;
template <class T>
static auto value_impl(...) -> std::false_type;
public:
template <class T>
static constexpr bool value = decltype(value_impl<T>(0))::value;
;
// To replace std::declval which yields T&&
template <class T>
T declrval();
#define is_specialization_of(...)
is_specialization_of<[]<class T>() -> decltype(__VA_ARGS__(declrval<T>())) >::value
// Usage
static_assert(is_specialization_of(std::array)<std::array<int, 4>>);
First caveat: Since we can't declare a parameter for the class template in any way without knowing its arguments, passing it around to where CTAD will be performed can only be done by jumping through some hoops. C++20 constexpr and template-friendly lambdas help a lot here, but the syntax is a mouthful, hence the helper macro.
Second caveat: this only works with movable types, as CTAD only works on object declarations, not reference declarations. Maybe a future proposal will allow things such as std::array &arr = t;
, and then this will be fixed!
Actually fixed by remembering that C++17 has guaranteed copy-elision, which allows direct-initialization from a non-movable rvalue as is the case here!
1
I'll deduce your template argument. ( I love this solution )
– Sombrero Chicken
Mar 28 at 13:29
@PasserBy I think so. Clang piles up errors on me, but GCC seems to be fine with it. If that weren't the case, I still have the option to use C++20's ability to wrap the lambda insidedecltype
and pass that type instead to reconstruct it later on.
– Quentin
Mar 28 at 13:29
1
@SombreroChicken Chicken Tortilla Argument Deduction?
– Quentin
Mar 28 at 13:30
1
Now we're talking about the good stuff.
– Sombrero Chicken
Mar 28 at 13:31
1
Just checked, expr.prim.lambda/2 is where it's forbidden, and it's gone in C++20.
– Passer By
Mar 28 at 13:37
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55396786%2fcheck-if-class-is-a-template-specialization%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
C++20 is a weird, weird world. Cross-checking is welcome as I'm a beginner with CTAD and not entirely sure I've covered all bases.
This solution uses SFINAE to check whether class template argument deduction (CTAD) succeeds between the requested class template and the mystery type. An additional is_same
check is performed to prevent against unwanted conversions.
template <auto f>
struct is_specialization_of
private:
template <class T>
static auto value_impl(int) -> std::is_same<T, decltype(f.template operator()<T>())>;
template <class T>
static auto value_impl(...) -> std::false_type;
public:
template <class T>
static constexpr bool value = decltype(value_impl<T>(0))::value;
;
// To replace std::declval which yields T&&
template <class T>
T declrval();
#define is_specialization_of(...)
is_specialization_of<[]<class T>() -> decltype(__VA_ARGS__(declrval<T>())) >::value
// Usage
static_assert(is_specialization_of(std::array)<std::array<int, 4>>);
First caveat: Since we can't declare a parameter for the class template in any way without knowing its arguments, passing it around to where CTAD will be performed can only be done by jumping through some hoops. C++20 constexpr and template-friendly lambdas help a lot here, but the syntax is a mouthful, hence the helper macro.
Second caveat: this only works with movable types, as CTAD only works on object declarations, not reference declarations. Maybe a future proposal will allow things such as std::array &arr = t;
, and then this will be fixed!
Actually fixed by remembering that C++17 has guaranteed copy-elision, which allows direct-initialization from a non-movable rvalue as is the case here!
1
I'll deduce your template argument. ( I love this solution )
– Sombrero Chicken
Mar 28 at 13:29
@PasserBy I think so. Clang piles up errors on me, but GCC seems to be fine with it. If that weren't the case, I still have the option to use C++20's ability to wrap the lambda insidedecltype
and pass that type instead to reconstruct it later on.
– Quentin
Mar 28 at 13:29
1
@SombreroChicken Chicken Tortilla Argument Deduction?
– Quentin
Mar 28 at 13:30
1
Now we're talking about the good stuff.
– Sombrero Chicken
Mar 28 at 13:31
1
Just checked, expr.prim.lambda/2 is where it's forbidden, and it's gone in C++20.
– Passer By
Mar 28 at 13:37
|
show 3 more comments
C++20 is a weird, weird world. Cross-checking is welcome as I'm a beginner with CTAD and not entirely sure I've covered all bases.
This solution uses SFINAE to check whether class template argument deduction (CTAD) succeeds between the requested class template and the mystery type. An additional is_same
check is performed to prevent against unwanted conversions.
template <auto f>
struct is_specialization_of
private:
template <class T>
static auto value_impl(int) -> std::is_same<T, decltype(f.template operator()<T>())>;
template <class T>
static auto value_impl(...) -> std::false_type;
public:
template <class T>
static constexpr bool value = decltype(value_impl<T>(0))::value;
;
// To replace std::declval which yields T&&
template <class T>
T declrval();
#define is_specialization_of(...)
is_specialization_of<[]<class T>() -> decltype(__VA_ARGS__(declrval<T>())) >::value
// Usage
static_assert(is_specialization_of(std::array)<std::array<int, 4>>);
First caveat: Since we can't declare a parameter for the class template in any way without knowing its arguments, passing it around to where CTAD will be performed can only be done by jumping through some hoops. C++20 constexpr and template-friendly lambdas help a lot here, but the syntax is a mouthful, hence the helper macro.
Second caveat: this only works with movable types, as CTAD only works on object declarations, not reference declarations. Maybe a future proposal will allow things such as std::array &arr = t;
, and then this will be fixed!
Actually fixed by remembering that C++17 has guaranteed copy-elision, which allows direct-initialization from a non-movable rvalue as is the case here!
1
I'll deduce your template argument. ( I love this solution )
– Sombrero Chicken
Mar 28 at 13:29
@PasserBy I think so. Clang piles up errors on me, but GCC seems to be fine with it. If that weren't the case, I still have the option to use C++20's ability to wrap the lambda insidedecltype
and pass that type instead to reconstruct it later on.
– Quentin
Mar 28 at 13:29
1
@SombreroChicken Chicken Tortilla Argument Deduction?
– Quentin
Mar 28 at 13:30
1
Now we're talking about the good stuff.
– Sombrero Chicken
Mar 28 at 13:31
1
Just checked, expr.prim.lambda/2 is where it's forbidden, and it's gone in C++20.
– Passer By
Mar 28 at 13:37
|
show 3 more comments
C++20 is a weird, weird world. Cross-checking is welcome as I'm a beginner with CTAD and not entirely sure I've covered all bases.
This solution uses SFINAE to check whether class template argument deduction (CTAD) succeeds between the requested class template and the mystery type. An additional is_same
check is performed to prevent against unwanted conversions.
template <auto f>
struct is_specialization_of
private:
template <class T>
static auto value_impl(int) -> std::is_same<T, decltype(f.template operator()<T>())>;
template <class T>
static auto value_impl(...) -> std::false_type;
public:
template <class T>
static constexpr bool value = decltype(value_impl<T>(0))::value;
;
// To replace std::declval which yields T&&
template <class T>
T declrval();
#define is_specialization_of(...)
is_specialization_of<[]<class T>() -> decltype(__VA_ARGS__(declrval<T>())) >::value
// Usage
static_assert(is_specialization_of(std::array)<std::array<int, 4>>);
First caveat: Since we can't declare a parameter for the class template in any way without knowing its arguments, passing it around to where CTAD will be performed can only be done by jumping through some hoops. C++20 constexpr and template-friendly lambdas help a lot here, but the syntax is a mouthful, hence the helper macro.
Second caveat: this only works with movable types, as CTAD only works on object declarations, not reference declarations. Maybe a future proposal will allow things such as std::array &arr = t;
, and then this will be fixed!
Actually fixed by remembering that C++17 has guaranteed copy-elision, which allows direct-initialization from a non-movable rvalue as is the case here!
C++20 is a weird, weird world. Cross-checking is welcome as I'm a beginner with CTAD and not entirely sure I've covered all bases.
This solution uses SFINAE to check whether class template argument deduction (CTAD) succeeds between the requested class template and the mystery type. An additional is_same
check is performed to prevent against unwanted conversions.
template <auto f>
struct is_specialization_of
private:
template <class T>
static auto value_impl(int) -> std::is_same<T, decltype(f.template operator()<T>())>;
template <class T>
static auto value_impl(...) -> std::false_type;
public:
template <class T>
static constexpr bool value = decltype(value_impl<T>(0))::value;
;
// To replace std::declval which yields T&&
template <class T>
T declrval();
#define is_specialization_of(...)
is_specialization_of<[]<class T>() -> decltype(__VA_ARGS__(declrval<T>())) >::value
// Usage
static_assert(is_specialization_of(std::array)<std::array<int, 4>>);
First caveat: Since we can't declare a parameter for the class template in any way without knowing its arguments, passing it around to where CTAD will be performed can only be done by jumping through some hoops. C++20 constexpr and template-friendly lambdas help a lot here, but the syntax is a mouthful, hence the helper macro.
Second caveat: this only works with movable types, as CTAD only works on object declarations, not reference declarations. Maybe a future proposal will allow things such as std::array &arr = t;
, and then this will be fixed!
Actually fixed by remembering that C++17 has guaranteed copy-elision, which allows direct-initialization from a non-movable rvalue as is the case here!
edited Mar 28 at 13:48
answered Mar 28 at 13:08
QuentinQuentin
49.2k6 gold badges97 silver badges154 bronze badges
49.2k6 gold badges97 silver badges154 bronze badges
1
I'll deduce your template argument. ( I love this solution )
– Sombrero Chicken
Mar 28 at 13:29
@PasserBy I think so. Clang piles up errors on me, but GCC seems to be fine with it. If that weren't the case, I still have the option to use C++20's ability to wrap the lambda insidedecltype
and pass that type instead to reconstruct it later on.
– Quentin
Mar 28 at 13:29
1
@SombreroChicken Chicken Tortilla Argument Deduction?
– Quentin
Mar 28 at 13:30
1
Now we're talking about the good stuff.
– Sombrero Chicken
Mar 28 at 13:31
1
Just checked, expr.prim.lambda/2 is where it's forbidden, and it's gone in C++20.
– Passer By
Mar 28 at 13:37
|
show 3 more comments
1
I'll deduce your template argument. ( I love this solution )
– Sombrero Chicken
Mar 28 at 13:29
@PasserBy I think so. Clang piles up errors on me, but GCC seems to be fine with it. If that weren't the case, I still have the option to use C++20's ability to wrap the lambda insidedecltype
and pass that type instead to reconstruct it later on.
– Quentin
Mar 28 at 13:29
1
@SombreroChicken Chicken Tortilla Argument Deduction?
– Quentin
Mar 28 at 13:30
1
Now we're talking about the good stuff.
– Sombrero Chicken
Mar 28 at 13:31
1
Just checked, expr.prim.lambda/2 is where it's forbidden, and it's gone in C++20.
– Passer By
Mar 28 at 13:37
1
1
I'll deduce your template argument. ( I love this solution )
– Sombrero Chicken
Mar 28 at 13:29
I'll deduce your template argument. ( I love this solution )
– Sombrero Chicken
Mar 28 at 13:29
@PasserBy I think so. Clang piles up errors on me, but GCC seems to be fine with it. If that weren't the case, I still have the option to use C++20's ability to wrap the lambda inside
decltype
and pass that type instead to reconstruct it later on.– Quentin
Mar 28 at 13:29
@PasserBy I think so. Clang piles up errors on me, but GCC seems to be fine with it. If that weren't the case, I still have the option to use C++20's ability to wrap the lambda inside
decltype
and pass that type instead to reconstruct it later on.– Quentin
Mar 28 at 13:29
1
1
@SombreroChicken Chicken Tortilla Argument Deduction?
– Quentin
Mar 28 at 13:30
@SombreroChicken Chicken Tortilla Argument Deduction?
– Quentin
Mar 28 at 13:30
1
1
Now we're talking about the good stuff.
– Sombrero Chicken
Mar 28 at 13:31
Now we're talking about the good stuff.
– Sombrero Chicken
Mar 28 at 13:31
1
1
Just checked, expr.prim.lambda/2 is where it's forbidden, and it's gone in C++20.
– Passer By
Mar 28 at 13:37
Just checked, expr.prim.lambda/2 is where it's forbidden, and it's gone in C++20.
– Passer By
Mar 28 at 13:37
|
show 3 more comments
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55396786%2fcheck-if-class-is-a-template-specialization%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm afraid what you want is not possible: stackoverflow.com/q/25893828/5470596
– YSC
Mar 28 at 11:56
1
Catching both
std::vector
andstd::array
can easily be done by adding anauto...
pack, but that would still only work if all type parameters comes first, and the non-types comes after. Catching a mixed pattern is AFAIK not possible.– super
Mar 28 at 12:01
@YSC That post is old, in C++17 new features such as
auto
for non-type parameter deduction were introduced, now maybe is possible. I haven't been able to find a way though.– user28032019
Mar 28 at 12:02
1
I think C++ compilers really really hate mixing types and values (hello most vexing parse) and tries to stay as far away as possible. Or in other words, this is impossible. Or @Quentin manages to abuse the most vexing parse again and wraps everything into one magnificent macro.
– Passer By
Mar 28 at 12:58
1
@PasserBy I'm sorry to disappoint, but the parser went through unscathed this time.
– Quentin
Mar 28 at 13:22