c++ - 以下语句是函数重载还是函数偏特化?

标签 c++ boost stl

template <typename Function> void for_each_element(
  const boost::tuples::null_type&, Function) {}

template <typename Tuple, typename Function> void     
  for_each_element(Tuple& t, Function func) {
    func(t.get_head());
    for_each_element(t.get_tail(),func);
}

根据上面的代码片段,我们是定义重载函数还是部分特化函数?

谢谢

最佳答案

不存在函数偏特化这样的东西。这是一个过载。

例如

template <typename T, typename U>
void foo(T t, U u);

template <typename T>
void foo<T, int>(T t, int u); // Illegal: no partial specialisation of functions

template <typename T>
void foo(T t, int u); // OK

小心 mixing specialisations with overloads ,因为它并不总是像您想象的那样工作。

关于c++ - 以下语句是函数重载还是函数偏特化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10668201/

相关文章:

c++ - 如何使主函数可以访问函数中的变量?

c++ - STL - 赋值运算符与 `assign` 成员函数

c++ - 如何让 char[] 与 std::map 一起工作

c++ - 用C++设置合并算法

c++ - Qt 使用 isAutoRepeat() 处理 QPushButton Autorepeat() 行为

c++ - 如何将 sizeof() 运算符应用于非静态类成员方法?

c++函数式编程(boost::phoenix && boost::spirit)测试指针占位符中的空指针

c++ - 存储稍后转发的变量参数

c++ - 使用 boost spirit x3 解析为递归变体的问题

c++ - BOOST_STRONG_TYPEDEF并 move 语义