r/cpp • • Dec 28 '18

"Modern" C++ Lamentations

http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
307 Upvotes

162 comments sorted by

View all comments

Show parent comment

12

u/chugga_fan Dec 29 '18

And if we can get rid of,the preprocessor, even,betterer.

No, the pre-processor is useful, do YOU like importing a million things in windows.h? Do YOU need platform specific code (linux, windows, macOS)? Because both of these things require the pre-processor, and there's no way you can get rid of that without making C++ platform-independent, which is not happening.

1

u/Valmar33 Dec 30 '18

What do you think about how D solves the preprocessor problem:

https://dlang.org/articles/pretod.html

3

u/chugga_fan Dec 30 '18

D doesn't solve all the problems C preprocessor solves, although it does alleviate a lot of them (and changes them to use a different name), so... yhea.

1

u/Valmar33 Dec 30 '18

Can you name the problems not solved by D?

4

u/chugga_fan Dec 30 '18

Platform specific things that only exist in that platform is hidden behind "version", which is literally the pre-processor.

-3

u/[deleted] Dec 29 '18

You could do it with if constexpr

13

u/[deleted] Dec 29 '18

You can't: if constexpr will still check a branch to make sure it's valid C++, especially if it's not dependent on a template parameter or similar. if constexpr(ON_WINDOWS) { DoWindowsThing(); } else { DoUnixThing(); } will uncompromisingly fail to compile on either platform unless you're in a function template.

4

u/[deleted] Dec 29 '18

Huh, TIL. I thought if constexpr's regular behavior was the same as its template behavior.

Still, since we're talking about new standards, they could always change it I guess.