Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: