C++函数模板问题

sky*_*gle 0 c++ templates

我正在寻找lcase/ucase C++ STL类的最佳方法,我遇到了这篇文章:

STL字符串为小写

给出的解决方案之一是:

#include <algorithm>
#include <string> 

std::string data = “Abc”; 
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
Run Code Online (Sandbox Code Playgroud)

但是,转换在stl_algo.h中定义为:

  template<typename _InputIterator, typename _OutputIterator,
       typename _UnaryOperation>
    _OutputIterator
    transform(_InputIterator __first, _InputIterator __last,
          _OutputIterator __result, _UnaryOperation __unary_op)
    {
...
Run Code Online (Sandbox Code Playgroud)

那么如何在不提供模板实例化参数的情况下调用呢?

为了澄清我的问题,我期待调用转换函数,如:

transform(std::string::iterator, std::string::iterator, 
          /* not sure what to put here for the predicate */);
Run Code Online (Sandbox Code Playgroud)

这是一次性(特殊情况),还是我遗漏了一些基本的东西?

Pra*_*rav 5

这称为模板参数演绎.

是另一篇很好的解释模板参数演绎的文章.