top | item 46152292

(no title)

raluk | 2 months ago

Years ago I wrote c++ library for stream compostion. Something like C++20 ranges. It turns out that as long as you compose everything with lambdas, compiled code is same as it would be with naive loops. Everything gets optimised.

For example, you can write sum of numbers less than n as:

  count(uint64_t(0)) 
   | take(n) 
   | sum<uint64_t>();
Clang converted this into n*(n-1)/2.

discuss

order

No comments yet.