1

I often use this macro to perfectly forward a parameter without having to know the type of the parameter:

#define FORWARD(a) std::forward<decltype(a)>(a)

I now want to get rid of the macro and therefore I'm searching for an equivalent definition of a function in c++ which can be used interchangeably with the macro.

This may be a simplistic example, but for the record: I want code like this to compile correctly with arbitrary types for Param{A,B} - without having to use the expanded form everywhere (like std::forward<decltype(a)>(a)).

decltype(auto) operator Op(ParamA a, ParamB b) {
    return Forward(a) Op Forward(b);
}

Hint: Not a duplicate of this question

nyronium
  • 1,258
  • 2
  • 11
  • 25
  • 1
    How about forwarding with a [unary `>>`](https://wg21.link/p0644)? :P – Rakete1111 Nov 13 '17 at 16:23
  • At first I though you were kidding, but actually thats a quite interesting approach! I'd like to see it in c++2a – nyronium Nov 13 '17 at 16:28
  • 1
    Of course, `std::forward` *is* the function for perfect forwarding. That's why we use it. Had it worked anyway, we wouldn't have had that function. – Bo Persson Nov 13 '17 at 16:28
  • 1
    If this is not a template (that is you know types `ParamA` and `ParamB`) then can't you just live without `std::forward` passing arguments manually? – user7860670 Nov 13 '17 at 16:28
  • Why would I use the macro then? I have to remove that redundancy, even though it seems unnnecessary. It might be just me, but it deeply disturbs me ;) – nyronium Nov 13 '17 at 16:34
  • 1
    Might want to read this: https://stackoverflow.com/questions/7779900/why-is-template-argument-deduction-disabled-with-stdforward/8862379#8862379 – PiotrNycz Nov 13 '17 at 16:50

0 Answers0