C++ Logo


Advanced search

Re: [std-proposals] Proposal for Uniform Forward And Move

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 22 Jun 2023 09:23:51 +0100
On Thu, Jun 22, 2023 at 7:40 AM Timur Doumler via Std-Proposals
<std-proposals_at_[hidden]> wrote:

> `name(name&&)` can now mean either a function type: `type(type&&)` or a function call with a forwarded parameter.

A function call with a forwarded parameter would be:

    void SomeFunc(int&&) {}

    int main(void)
        int monkey = 7;
        SomeFunc(monkey&&); // not there is no 'void' here

And a function declaration would be:

    void SomeFunc(int&&) {}

    int main(void)
        typedef int monkey;
        void SomeFunc(monkey&&); // Note that this has 'void' at the beginning

I think the parser can easily see that the latter example begins with
"void", and can thus disambiguate easily.

Another one to consider is:

    std::function< something(something&&) >

If the template is expecting a type parameter rather than a value
parameter, then it's easy to disambiguate. If there is more than one
template overload, and if one can take a type, and another can take a
value, then it would only be tricky if 'something' were the name of a
class with a constexpr constructor.

    class Monkey { constexpr Monkey(void) {} };

    some_template< Monkey(int&&) > my_object;

Actually I just realised that we already have this 'problem' in the
language, and I think it's only 'std::function' that's affected
because it cannot be implemented without compiler support.

Received on 2023-06-22 08:24:03