I encountered this "beautiful" example of "highly readable" and "elegant" code, but I'm having troubles understanding it:
struct S {
[[noreturn]] virtual inline auto f(const unsigned long int *const)
–> void const noexcept;
};
Here's what I understand (please correct me if I'm wrong):
f()
is a member function ofS
virtual
- can be overridden by derived classesinline
- compiler should attempt to generate code for a call tof
rather than calling it normallyconst
- the function is not able to change any ofS
's membersnoexcept
- the function will never throw (cannot throw or not allowed to throw)- parameter: a
const
pointer to aconst unsigned long int
auto .... -> void
- suffix return typevoid
[[noreturn]]
- it neverreturn
s
Here are my main concerns:
- If a function is declared as
[[noreturn]]
, it never returns to its caller; so how can it have a return typevoid
? What is the point of a return type in this function anyway? - Would this code compile with
int
instead ofvoid
for example? - What would be a practical use for a function like that? To throw an exception?
- Where does the flow of the code go after this function finishes executing (after
}
)?
I couldn't get this code to run on VS2013 Preview, so I guess these features weren't implemented yet.
I'm very curious about this, so I'll appreciate it if someone can explain! Cheers
[[noreturn]]
means. I need help, that's why I'm asking. – Oleksiy