The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
traits + "constexpr if" replace SFINAE.
A quick primer on type traits in modern C++
21–30 of 38 posts
Re: A quick primer on type traits in modern C++
#22I found the use of 'if constexpr' in the example pretty nasty. I would have thought it more idiomatic to use std::enable_if to enable different implementations of 'algorithm' as in the example of 'construct' and 'destroy' given here: https://en.cppreference.com/w/cpp/types/enable_if
The right solution are of course concepts.
Re: A quick primer on type traits in modern C++
#23The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
Not a whole lot, actually. You can go from C to this in about a week if you’re focused. (I did this a few years ago when learning C++. Now if you want to talk about initialization, that’s a whole ‘nother story…)
Re: A quick primer on type traits in modern C++
#24The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
Re: A quick primer on type traits in modern C++
#25The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
Re: A quick primer on type traits in modern C++
#26The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
I think that’s unfair. While “sfinae’ itself is a mouthful, what it says in practice is that template expansion observes the principle of “least surprise” which is inherently user friendly.
You certainly don’t need to know the acronym, or even of the idea, to benefit from it. I stead, the developer won’t be presented with a confusing error message when the thing they want to happen is supported but not the first possibility examined.
Re: A quick primer on type traits in modern C++
#27The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
It just looks kinda wrong to me - If your generic template has to switch on what type it's been passed, surely you've made it too generic somewhere? Adding back conditional compilation or execution afterwards strikes me as the same sort of code-smell as checking if something is an instance of a given class before then casting it and calling a member - you've lost information and using some sort of reflection to get i…
Re: A quick primer on type traits in modern C++
#28The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
I mean, even if you never saw a "constexpr" before, isn't it pretty clear from the example and the name, well, "constexpr" want's going on? Same for the other newish C++ features.
I thought it was a nice little primer.
Re: A quick primer on type traits in modern C++
#29The amount of background knowledge you need to understand what’s happening here... I don’t envy people who have to catch up becoming more and more convinced that when sfinae opened the Turing hatch it doomed c++
> …when sfinae opened the Turing hatch it doomed c++… I think that’s unfair. While “sfinae’ itself is a mouthful, what it says in practice is that template expansion observes the principle of “least surprise” which is inherently user friendly. You certainly don’t need to know the acronym, or even of the idea, to benefit from it. I stead, the developer won’t be presented with a confusing error message when the thing t…
The argument is I think, that because sfinae effectively added an "if" statement to C++ templates, it made templates turing complete. It made it possible to write all kinds insane, undebuggable programs purely at compile-time, in the most terrible purely functional language imaginable. People did exactly that, which went fine until their colleagues (or users of open source libraries) did something unexpected and got screenfuls of errors.
Wikipedia's sfinae page has a nice story about how it added compile-time introspection and conditionals to the language: https://en.wikipedia.org/wiki/Substitution_failure_is_not_an...
Re: A quick primer on type traits in modern C++
#30I found the use of 'if constexpr' in the example pretty nasty. I would have thought it more idiomatic to use std::enable_if to enable different implementations of 'algorithm' as in the example of 'construct' and 'destroy' given here: https://en.cppreference.com/w/cpp/types/enable_if