相关疑难解决方法(0)

Why does the following program not select the argument of the same type as the first template parameter?

I am trying to write a function such that f<T>(args..) returns the first parameter of type T.

The following program seems to always select the first specialization thus printing 97 (ASCII code of 'a'). Though the second one wouldn't require converting char to int. Could someone please explain the behavior?

I am new to SFINAE and meta-programming.

  #include <iostream>
  using namespace std;

  template <typename T, typename ...Ts>
  T f(T a, Ts... args) {
    return a;
  }

  template …
Run Code Online (Sandbox Code Playgroud)

c++ templates sfinae variadic-templates c++14

6
推荐指数
2
解决办法
239
查看次数

标签 统计

c++ ×1

c++14 ×1

sfinae ×1

templates ×1

variadic-templates ×1