• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: type trait with enum as specialisation

Resolved: type trait with enum as specialisation

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I would like to have a type trait that would be false for any parameter T except for the enum value Http::Get
However, it seems that the c++ compiler does not allow me to specialise a template class with an enum when the first is a typename.
If I instead do :
it works!
Any reason why that is the case, and what are the workarounds to achieve what I want.
I basically want the compiler to return the type trait to false even when T is not of a enum type Http

Answer:

typename and class expect types. Http::Get is (presumably) not a type, but a value, like any other constant (42, 'A', false etc.). And you obviously cannot pass a value when a type is expected.
The solution would be different depending on your use cases. For example:

If you have better answer, please add a comment about this, thank you!

c++ templates typetraits
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to scroll bottom of div at launch?

02/04/2023

Resolved: how to get and read an xml file in a zip file using xml.etree

02/04/2023

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.