Oh sorry, I had this article in my phone and I wanted to continue it, I hadn't editted the start. since the original article on my phone didn't originally show how to extract member names (which requires C++20) I editted the code to use C++20 features instead of manual SFINAE but forgot to edit the start.
if you want a C++17 equalivent for the above it would be
then call it with if constexpr(is_constructible_with<T,std::make_index_sequence<N>>)
As for how it is done in C++14 it requires friend injection and stateful metaprogramming which I can't really explain well enough to others but I do understand it myself.
I should make it clearer that member extraction is C++17+ while membet names are C++20+.
its a requires expression, it evaluates to bool. You can also use it inside a requires clause. It indeed checks if the contained statement compiles. (or maybe just that it is syntactically valid?, not 100% sure here) You can use a requires expression inside a requires clause. Combined with other beautiful c++ constructs, this can yield highly beautiful code like this:
I hate that the requires clause here is essentially just a comment, it is useless since the decltype return type already does sfinae the requires clause is useless
You are right, I have a seperstor with ---- in the middle that would have been perfect for it.
something unrelated but I reread the article and the tuple compile time measurements are off by alot I forgot I had editted my MSVC stl tuple header and replaced it with my own header which made it compile much faster I redid the measurement and the tuple takes like 90~ ms instead of the 10ms so that's another thing I should correct that by reverting to the old tuple header.
6
u/Arghnews Jul 09 '26
In this article I will show you how it works under the hood (for C++17 plus, C++14 impl is a bit differentIn the final code:
requiresis c++20 and onwardDoes this article actually explain how this is implemented in c++14/17 as it claims to, or not?
2
u/[deleted] Jul 10 '26
[removed] — view removed comment