today I came across this weird code:
auto rovoid_iterator
    (
        Construct ROII* const at,
        auto(ROII&)(auto(*)(Str&&)noexcept->void) ->void //WTF??
    ) -> void;
What the hell is this weird second parameter??
Thanks in advance!
C++ has two ways to pass a function as a parameter. As you see, you can use either operation() or operation2() to give the same result.
Function Call When calling a function with a function parameter, the value passed must be a pointer to a function. Use the function's name (without parentheses) for this: func(print);
Okay, let's deconstruct this abomination.
First, there's a inner type:
auto(*)(Str&&) noexcept -> void
This is a pointer to function taking a Str rvalue-reference as parameter. It's also a noexcept function.
Let's call that S
using S = auto(*)(Str&&) noexcept -> void;
Then the outer part of the parameter can be subtitued like that:
auto(ROII&)(S) -> void
As you stated in the comments, ROII is an empty macro. So in the end it reads like that:
auto(&)(S) -> void
That code appear to be a parameter which would be a reference to function that take a S which is and return void.
Okay I asked the dev who wrote this:
auto(ROII&)(auto(*)(Str&&)noexcept->void) ->void 
Is a reference to a function which takes a function pointer as argument. This function pointer is a pointer because its okay to pass nullptr if you dont need it, but the first function must be passed thats why it is a reference. The second pointer is a pointer to a function wich is noexcept and takes a rvalue reference to a string as paremeter. ROII marks game ready functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With