"I think that it's extraordinarily important that we in computer science keep fun in computing."
-- Alan J.Perlis
Dedication, SICP
https://www.youtube.com/watch?v=7oV7hiAsVTI
#cppcon #cpp #SICP
@codewiz are the `auto` for "our types are too long to type" or "we are just lazy" ? π
@Matthieu Answering your question requires introducing certain... concepts π
@Matthieu Ok, I must do it. It's too elegant. Too beautiful.
That auto in the parameter list is a C++20 shortcut syntax for templates:
template<typename T>
auto fib(T n) {
...
}
He says "C++20 concepts" in the slide because you could also throw in a concept right there:
auto fib(std::integral auto n) {
...
}
And this would _still_ be a template function, just not one that accidentally concatenates strings just because they had an operator+()
@Matthieu Now that I look at it a bit more, fib() being a template is kind of dumb, because immediately afterwards he forces the type to int for the nested lambda fib_iter.
So, even you passed a long long, it would get truncated to an int in the recursive step!
Going generic there would require naming the type, which brings back the full blown template syntax π€¦ββοΈ
Isn't that elegant?
@codewiz I just had to do it:
http://ix.io/2B03/cpp
It's like exactly the same trick he used with the a and b to optimize fibonacci, except in case of self reference you actually need that trick cause the lambda does not have a type name, while a and b are states and as such belong in the capture list more than the self reference. Sooo much angeeer!
@Matthieu