C++ Insights

#include <type_traits> #include <cassert> template<typename T> auto getValue(T t) { if constexpr(s

@tmr232 Well, yes, that's what's on the image :) The std::min is just an example of usage (which I do agree is a bit confusing)
@gynvael
Oh no. Isn't it a bit late for a Halloween scare?

@gynvael wat

i thought std::endl was a platform dependent constant??

@meena In all honesty that's what I thought as well for years! Then, when I was writing some article or something, I wanted to find the exact definition in the headers... and found a function.

After checking in the standard's draft (http://eel.is/c++draft/ostream.manip#2) it turned out that apart from this being a platform specific constant, it also does a flush() 🤷

[ostream.manip]

@gynvael why wouldn't that be a separate function??
@meena I have only my guesses, which are:
- perhaps endl is the de facto "separate function" you mention, as basically all modern platforms use \n as the end of line anyway, so there's no need for a function that emits a platform specific character (i.e. one can just include \n at the end of the string vs using the separate function which also does a flush)
- or the authors wanted to make sure that the buffer is flushed with every new line for UX purposes; this is actually in line with other places in the standard library where there is code adding a flush after each \n (e.g. stdout is line buffered by default when connected to a terminal).
@gynvael I’ve seen the |0 method show up a lot in the creative code community lately.

@probably Yeah, TBH I use it as well. It has however a nasty side effect - it also truncates numbers number to a 32-bit integer value (even though JS's number type can store integers safely to around 2**53ish).

0x7fffffff|0
2147483647

(0x7fffffff+1)|0
-2147483648

(0x100000000)|0
0

@gynvael off-topic, but I have to know the name of this font!