• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Enabling C++ constructor subject to say std::is_floating_point

Resolved: Enabling C++ constructor subject to say std::is_floating_point

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve Enabling C++ constructor subject to say std::is_floating_point<T>

Question:

I’m trying to enable a default constructor only if the class’s template parameter is floating point. Note T is not a parameter type nor return type but the class template type.
I tried putting the following in front of the constructor
And I tried putting the std::enable_if_t...= true stuff as an argument to the default constructor (and various other attempts).
Both of these tries rightfully complains about it1 so that’s good, but when I remove that, they both also complain about it2! I don’t understand and can’t find the magic incantation.
Thanks for any insights.
I forgot to mention, I’m stuck on C++17.

Best Answer:

Use requires:
Or, in C++17:
The SFINAE condition must depend on a template parameter of the function itself. Otherwise it can be checked when the class is first instantiated, even if the function isn’t used.
I also tweaked a few things, purely for style.

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

Source: Stackoverflow.com

c++ constructor enable-if template-meta-programming templates
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: net::ERR_HTTP2_PROTOCOL_ERROR by http get request angular 15.2

02/04/2023

Resolved: How do I stop the command from happening if the requirements for it to work aren’t sert Discord.js

02/04/2023

Resolved: How to scroll bottom of div at launch?

02/04/2023

Comments are closed.

© 2023 DEVSFIX.COM

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