3 ms·
Yep, it was made jokingly trying to make a point about the slippery slope of 'bloat'. But didn't go that well.
by rwbt 8y ago
Yep, it was made jokingly trying to make a point about the slippery slope of 'bloat'. But didn't go that well.
- AnimalMuppet 8y agoIt went all right, once I adjusted my sarcasm detector...
- nrclark 8y agoOut of curiosity, would you consider constexpr to be bloat? I feel like it has tons of applications, especially for embedded C programmers. One example that comes to mind: CRC calculation. Most microcontroller CRC libraries are lookup-based, or a mixture of a lookup table and other methods. Currently, a lookup table can be done only 3 ways in C: pre-compute it and store 'magic numbers' (either while developing, or with some custom pre-processing), compute at program initialization (which costs code-space and startup time), or a compile-time computation based on some very ugly macros. With constexpr support, I could just write a C function that calculates the table values. Then I could use it to populate a constexpr table at compile time, or even use the function at runtime if I needed to do some debugging. C already has sizeof, which is a compile-time computation. Why not let users write their own compile-time functions too? I recently wrote a command-lookup library in C++14. Using constexpr, I could precompute the hashes of each string and populate a switch() statement. Plus I could use the exact same function to hash my incoming strings, even if they're of unknown length. That's not possible in C at all, not even with loop-based macro trickery.
- rwbt 8y agoI think constexpr is a great feature. But without templates (or meta programming in general) I feel like it's severely limited in it's uses (although you cite a great use case). Adding templates is another whole can of worms (for templates to be really useful, add operator overloading too? so on..)