It’s a version of a for loop that is evaluated at compile time (or, at least, can be evaluated at compile time if the arguments can also be evaluated at compile time). I couldn’t easily find a reference to Zig’s inline for (both words are common on the Internet, and even in combination with Zig find a lot of unrelated things), is that the same?
I really like this general construction. I’ve done something similar to this with a recursive template, but specialised for a specific use. Their version is a generic template that takes a constexpr lambda (or any other constexpr object with a constexpr call-as-function overload, though lambdas will be the most common).
It’s a version of a for loop that is evaluated at compile time (or, at least, can be evaluated at compile time if the arguments can also be evaluated at compile time) […], is that the same?
Yes, sounds right. I’m still getting used to it, but several times I’ve revisited old code and noticed something I could clean up by using inline for.
Edit: Just saw a good example of it in another post on here.
I don’t always understand what advanced C++ tricks are
for
, but this looks like Zig’sinline for
, which I find very useful.It’s a version of a for loop that is evaluated at compile time (or, at least, can be evaluated at compile time if the arguments can also be evaluated at compile time). I couldn’t easily find a reference to Zig’s
inline for
(both words are common on the Internet, and even in combination with Zig find a lot of unrelated things), is that the same?I really like this general construction. I’ve done something similar to this with a recursive template, but specialised for a specific use. Their version is a generic template that takes a
constexpr
lambda (or any otherconstexpr
object with aconstexpr
call-as-function overload, though lambdas will be the most common).Yes, sounds right. I’m still getting used to it, but several times I’ve revisited old code and noticed something I could clean up by using
inline for
.Edit: Just saw a good example of it in another post on here.