1

Why do we receive an error when explicitly providing the template arguments as below?

#include <tuple>
int main()
{
    int a = 1;
    int* ap = &a;
    // std::make_tuple<int*, int>(ap, a); // cause error "cannot bind rvalue reference of type 'int*&&' to lvalue of type 'int*'
    std::make_tuple(ap, a); // fine
}
DXZ
  • 451
  • 4
  • 14
  • 2
    Do note that the whole purpose of the make functions is to not have to specify the type (expect make_unique and make_shared). – NathanOliver Jan 17 '20 at 19:43
  • @NathanOliver, thanks for the reminder. I think in some cases, e.g., feeding literal values, we still need explicit arguments to be unambiguous? – DXZ Jan 17 '20 at 19:56
  • In any cases when you need to be explicit there's no advantage in using these functions over the constructor like `std::tuple(....)`. And literal values are not ambiguous anyway, so this is not that case. – Ruslan Jan 17 '20 at 20:02
  • @DXZ That is what user defined literals and the built in literals are for. If you want a `long`, use `0L`, `long long`, use `0LL`. – NathanOliver Jan 17 '20 at 20:20

0 Answers0