相关疑难解决方法(0)

C++中模板参数中auto的优点17

auto在(可能)用C++ 17引入的模板参数中有哪些优点?

它只是auto我想要实例化模板代码的自然扩展吗?

auto v1 = constant<5>;      // v1 == 5, decltype(v1) is int
auto v2 = constant<true>;   // v2 == true, decltype(v2) is bool
auto v3 = constant<'a'>;    // v3 == 'a', decltype(v3) is char
Run Code Online (Sandbox Code Playgroud)

我还从这个语言功能中获得了什么?

c++ templates auto c++17

51
推荐指数
4
解决办法
2万
查看次数

有没有办法在PC中将auto作为参数传递?

有没有办法将auto作为参数传递给另一个函数?

int function(auto data)
{
    //DOES something
}
Run Code Online (Sandbox Code Playgroud)

c++ arguments function auto

35
推荐指数
3
解决办法
2万
查看次数

功能模板与自动关键字

autoC++ 11中的关键字可以替换函数模板和特化吗?如果是,使用模板函数和特化而不是简单地键入函数参数有什么好处auto.如果没有,我完全期望被投入到地狱中,但我是C++的新手,但所以请放轻松我.

template <typename T>
void myFunction(T &arg)
{
    // ~
}
Run Code Online (Sandbox Code Playgroud)

void myFunction(auto &arg)
{
    // ~
}
Run Code Online (Sandbox Code Playgroud)

c++ templates auto

23
推荐指数
3
解决办法
5587
查看次数

标签 统计

auto ×3

c++ ×3

templates ×2

arguments ×1

c++17 ×1

function ×1