samedi 19 octobre 2019

What are the name lookup and type simplification rules for trailing return types?

Trailing return types allow to simplify code in these two scenarios:

  1. Returning a type defined inside the class from one of the class's member functions:

    struct X
    {
        using foo = int;
        foo f();
    };
    
    // pre-C++11
    X::foo X::f()      { /* ... */ }
    
    // trailing, doesn't require `X::` before `foo`
    auto X::f() -> foo { /* ... */ }
    
  2. Returning a complicated type, such as a function pointer type:

    // pre-C++11
    int(*g(float))(int) { /* ... */ }
    
    // trailing, easier to read
    auto f(float) -> int(*)(int) { /* ... */ }
    

I am trying to find the relevant parts of Standard that explain how the above two simplifications work. I've looked at [basic.lookup] and grepped for trailing-return, but couldn't find anything straightforward that explained how the above transformations work.

Have I missed it?

What parts of the Standard explain the above trailing-return-type simplifications?

Aucun commentaire:

Enregistrer un commentaire