C++ Logo

std-discussion

Advanced search

Positioning the && after the ...

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 30 Nov 2023 10:26:24 +0000
Both g++ and clang++ fail to compile the following code. The only
difference between Func1 and Func2 is where I have placed the '&&'.
Func2 is accepted but Func1 is rejected.

#include <utility> // forward

template<typename T, typename... Ts>
T &Func1(char unsigned *const p, Ts... &&args)
{
    return *::new(p) T( std::forward<Ts>(args)... );
}

template<typename T, typename... Ts>
T &Func2(char unsigned *const p, Ts&& ...args)
{
    return *::new(p) T( std::forward<Ts>(args)... );
}

Are both of these syntaxes supposed to be accepted by every compiler?

The syntax of Func1 makes more sense because we have to define
variables as follows:

    int &&a = monkey, &&b = donkey, &&c = fish;

That is to say: The '&&' goes with the name -- not with the type.

Received on 2023-11-30 10:26:36