I
I
Insolent Muzzle2021-01-01 22:44:34
C++ / C#
Insolent Muzzle, 2021-01-01 22:44:34

Why doesn't std::endl require parentheses?

std::endl is a function, but does not require parentheses when used with std::ostream (perhaps this applies to all std::basic_ostream descendants in general, I have not tested and would be grateful if you tell). How so? I have an assumption that there is a separate overload of the << operator specifically for the pointer (or what gives a function call without parentheses?) to this function. Is it real?
std::cout << std::endl; // Абсолютно валидный код

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2021-01-01
@pluffie

Yes, it really is. Moreover, if you wish, you can write your own - for example , as in my miniature log class:

Lout& operator << (Lout& out, Lout& (*func)(Lout&));
Lout& operator << (Lout& out, std::function<Lout& (Lout&)>&&func);

//stream commands & modifiers
Lout &anounce(Lout &ret);
Lout &flush(Lout& out);
Lout &ok(Lout& out);
Lout &fail(Lout& out);
Lout &newLine(Lout& out);
Lout &pop(Lout& out);
Lout &Color(Lout& out, const uint8_t);
Lout &noColor(Lout& out);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question