5 ms·
Ugh, so much wrong with this. There is C++, as implemented by every compiler, and then there is fantasy C++, as seen by the committee... See, e.g. this trainwre
by 112233 9y ago
Ugh, so much wrong with this. There is C++, as implemented by every compiler, and then there is fantasy C++, as seen by the committee... See, e.g. this trainwreck:
https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/rt2ivJnc4hg%5B1-25%5D
Also, e.g.
> P.6: What cannot be checked at compile time should be checkable at run time
Great! I want to do it! later...
> F.4: If a function may have to be evaluated at compile time, declare it constexpr
Ok. You can't put static_assert in constexpr function. You can't put runtime assert in constexpr function. You can't put debug print in constexpr function. How do you even debug that?
- pjmlp 9y ago> You can't put debug print in constexpr function. How do you even debug that? Use an IDE.
- 112233 9y ago> Use an IDE. Explain.
- pjmlp 9y agoIDEs provide graphical debuggers and colorization to show which code actually gets compiled. For example on Visual Studio, paths not taken on conditional code get grayed out.
- oblio 9y agoYou disappoint me pjmlp, you're not a true graybeard unless you use Vim or Emacs :o) The slightly more serious question: is there anything like this in Vim or Emacs-land? I somehow doubt it... I, for one, have never seen something like it outside of the big IDEs (Visual Studio, IntelliJ, etc.)
- pjmlp 9y agoI am an ex-XEmacs user, and used vi on Xenix, DG/UX if that makes you happy. :) Always been an IDE fan since Turbo Pascal 6.0 with its Turbo Vision based IDE.
- elbows 9y agortags for Emacs does this, as well as completion, highlighting syntax errors, and various other IDE-like features.
- oblio 9y agoGot any demo for that? I couldn't find the "highlight unused code" thing...
- humanrebar 9y ago> How do you even debug that? You provide a set of static assertions for the use cases you aren't sure of. constexpr functions should be thoroughly unit testable at compile time. If you're worried about production compile times, put the static assertions in your test code.
- 112233 9y agoAgree about unit tests. But asserts are used also to catch invalid _use_ of functions. void f(size_t x) { assert(x); // calling f with 0 is bug } constexpr f(size_t x) { ?????(x != 0); // <- what to write here? }
- jcelerier 9y ago> How do you even debug that? constexpr int hard_stuff(int x, int y) { return x + y; } void hard_stuff_test() { static_assert(hard_stuff(2, 3) == 5); } ?
- IshKebab 9y agoI agree, e.g. they recommend not using `#pragma once` because: > It injects the hosting machine's filesystem semantics into your program, in addition to locking you down to a vendor. Our recommendation is to write in ISO C++ Erm. What. Compiling anything other than a one-file program "injects the filesystem semantics into your program". I mean... your program is stored in a filesystem. #include uses a filesystem. What utter tosh. And as for locking you down to a vendor, even niche compilers that you've probably never heard of support it. https://en.wikipedia.org/wiki/Pragma_once#Portability https://en.wikipedia.org/wiki/Pragma_once#Portability I'd take anything from there with a boulder of salt.
- izacus 9y agoHrmf, what I think they tried to say is that #pragma once causes your code to compile differently depending on which file it's stored inside. This can cause problem with some tooling (e.g. precompiled header generators, some distributed compiler tools, etc.) which concatenate header and source files to generate an amalgam. So it's not "tosh", it probably just doesn't correspond to your way of writing C++ code.
- smitherfield 9y ago>You can't put runtime assert in constexpr function. As of C++17 you can: http://en.cppreference.com/w/cpp/error/assert http://en.cppreference.com/w/cpp/error/assert You can also throw exceptions in constexpr functions since C++14.