Just a bit of nitpicking. =delete is available also since C++11 according to CppReference
=delete
Regarding concepts, it's worth to note (?) that in case you only want to accept numbers (I'm a bit vague) you have 4 different ways:
#include <concepts> #include <iostream> template <typename T> concept Number = (std::integral<T> || std::floating_point<T>) && (not std::same_as<T, bool>); template <typename T> requires Number<T> T f(T t) { return 2 * t + 3; } template <typename T> auto f2(T t) requires Number<T> { return 2 * t + 3; } template <Number T> auto f3(T t) { return 2 * t + 3; } auto f4(Number auto t) { return 2 * t + 3; } int main () { std::cout << f(2) << std::endl; std::cout << f2(2.2) << std::endl; std::cout << f3(3) << std::endl; std::cout << f4(-2.4) << std::endl; // std::cout << f2(true) << std::endl; // auto f2(T) requires Number<T> [with T = bool]' with unsatisfied constraints }
I'll write a more detailed post about the 4 ways of concepts.
_Please note that the concept Number is incomplete, it accepts char for example _
Number
char
This is not being "nitpicking": this is being "accurate". Thanks! I fixed that.
In fact, I missed this warning:
warning: deleted function definitions are a C++11 extension [-Wc++11-extensions]
I have not really dived into concepts yet, so I am really interested by your future article!
PS: I have added a PS to my article above ; )
Gosh, I started that article, and it's already longer than the whole series on constness. I'll have to break it down :)
Not surprising XD
Thanks a lot for the PS :)
I have to start writing that article soon!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just a bit of nitpicking.
=delete
is available also since C++11 according to CppReferenceRegarding concepts, it's worth to note (?) that in case you only want to accept numbers (I'm a bit vague) you have 4 different ways:
I'll write a more detailed post about the 4 ways of concepts.
_Please note that the concept
Number
is incomplete, it acceptschar
for example _This is not being "nitpicking": this is being "accurate". Thanks! I fixed that.
In fact, I missed this warning:
I have not really dived into concepts yet, so I am really interested by your future article!
PS: I have added a PS to my article above ; )
Gosh, I started that article, and it's already longer than the whole series on constness. I'll have to break it down :)
Not surprising XD
Thanks a lot for the PS :)
I have to start writing that article soon!