5

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!

18
  • 3
    Lookup "trailing return type in C++". Commented Aug 13, 2019 at 17:34
  • 12
    I think the technical term for that kind of parameter is "abomination". Commented Aug 13, 2019 at 17:34
  • I know these trailing return types but what is this parameter? A pointer a reference and to what? Commented Aug 13, 2019 at 17:35
  • it looks to me like an argument that wants a function which has one argument whose type is itself a pointer to a function which in turn takes an Str&& as argument and they all return void. Or I may be confused. Commented Aug 13, 2019 at 17:36
  • 1
    @Noel2019 "It is for sure it compiles with c++ 17 and msvc" - Just because something compiles does not always mean it is valid. "It compiles" is a very low bar and in no way guarantees correctness. Commented Aug 13, 2019 at 17:45

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Interesting to note that the parameter does not appear to have any sort of name. Maybe it has one in the definition.
@FrançoisAndrieux not so surprising. This is a function declaration, parameters don't need names there.
Ninja'd by my edit. But note that at has a name, so it was decided that the first argument deserved a name in the declaration but not the second.
Thank you ;) The same as the author said
@FrançoisAndrieux nice catch. This is indeed suspicious
|
4

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.

7 Comments

Could you ask him... why? Why in the name of all that is good, would he feel the need to do this?
@J.AntonioPerez It's the modern evolution of the three star programmer. Maybe the three lambda programmer or something.
I will ask him ;) wait and what does three star programmer mean? Oh didnt see the link never mind
A "three star programmer" is a programmer who writes unnecessarily complicated code, partly because they want to show off how smart they are. Generally speaking, it's frowned upon. The name comes from people who'd use pointers to pointers to pointers (like int***, which has three stars after the int).
To be honest, that style of programming makes him a liability to his team. Complicated code is more difficult to maintain; harder to debug; harder to modify to fit the needs of future projects; and it oftentimes ends up being slower in the long run.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.