Following this popular question, present your solution which prints the numbers 1 to 1000 (all of them, not the string "1 to 1000" verbatim or something funny) in C++ without using any semi-colons. Unlike the original question, you may use conditionals and loops.
Solutions not requiring any comp...
> If a constexpr function or constructor is called with arguments which aren't constant expressions, the call behaves as if the function were not constexpr, and the resulting value is not a constant expression. Likewise, if the expression in the return statement of a constexpr function does not evaluate to a constant expression for a particular invocation, the result is not a constant expression.
Your header file should usually not contain code, unless it is the code of static inline functions or of template functions. And you should compile with g++ -Wall -g. And intuitively, header files are "smaller" (since they should contain more declarations than definitions) than source files. — Basile Starynkevitch1 min ago
The only time it is probably worth using is when the compile-time version would be implemented in the exact same way as the run-time version, which is very very rare
@StackedCrooked I was referring to the comment which claimed that functions in header files should be static inline and I was wondering if static free functions are possible at all.
@bamboon - yes, static inline in that context means not visible outside of the scope of the unit/.cpp file that includes it (internal linkage as Pubby stated) and inline so you don't get a multiple-definition linkage error should that header file be included by more than one .cpp (since you are embedding it inside the header rather than have the implementation in a .cpp, as in the usual case)
Disclaimer: I have no idea what concepts are (I know what they represent, just not how and when they are useful/used, etc.). Don't bother educating me right now. I'll be gone in a minute :p
@Xeo bah, I still would like to see a more lenient normal if: if(bla()) auto t = something(); else auto t = something_else(); do_something(t); should be possible.
As a side note, the parameters to a function being called are also following the same rule: left to right. However, Visual C++ (cl) compiles right to left in debug mode. Something to keep in mind. Although it is somewhat different from the command operator per se. — Alexis Wilke19 mins ago
I'm reading text from file. I can not read the whole file at once, it might be very big. Is it better practise to keep my file opened or to close and open it dozens of times?
Probably I can, but that's not a point. I'm writting something like linux "less" command and reading the entire file at once is just... wrong. It might cause my program to slow down and consume lots of RAM
@leftaroundabout With the built-in comma operator (i.e. no user-defined overloads), both (a, b), c and a, (b, c) will evaluate a, b and c (in that order) and yield the result of c. How is that not equivalent? — FredOverflow34 secs ago
Why would they be equivalent? Not even (a + b) + c and a + (b + c) are guaranteed to be equivalent. (They aren't in floating-point arithmetic for accuracy reasons, and in some exotic number systems they aren't even supposed to). — leftaroundabout2 hours ago
I don't see how , relates to + or other operators.
If you have five things to evaluate, do you evaluate the first thing first, and the remaining four after that? Or do you evaluate the first four things first, and the last thing after that? I think it does not matter.
@FredOverflow Elements of Programming chapter 3 is about associativity. (It illustrates how its properties can be used to implement the power function efficiently.)