Hacker News new | ask | show | jobs
by Someone 2209 days ago
“there's not even an efficiency benefit from doing this. You'd have a more efficient and literate program with std::iota“

I would pick a different syntax, too, but this is more flexible than std::iota. You can do v+=a,b,c, for example.

I also would think any decent compiler would completely optimize away that appender instance, making it quite efficient for short lists of items (for longer lists, compiling a push_back call for each item would get inefficient, memory and cache-wise. I don’t see a compiler converting that into a loop)

1 comments

An optimizer can do many things until it cannot. Since you have no easy way to assert the overall performance of your program, you may end up with broken optimizations at some point in the future due to unrelated changes, pretty much non-deterministically.

In addition, more templates and more types means way less compiler throughput. That is why major parts of Boosts are avoided.

Not to mention human throughput too.

> compiling a push_back call for each item would get inefficient, memory and cache-wise?

That depends a lot on what you are doing.

By the way, if you are dealing with tons of constants in your code, then it usually means the design of the application is likely inflexible and a code smell overall.