假设我有一个functionProxy带有泛型参数的函数function并调用它operator():
template< typename Function > void functionProxy( Function function ) {
function();
}
Run Code Online (Sandbox Code Playgroud)
传递给它的对象可能是:
一个仿函数:
struct Functor {
void operator()() const {
std::cout << "functor!" << std::endl;
}
};
Run Code Online (Sandbox Code Playgroud)功能:
void function( ) {
std::cout << "function!" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)一个(C++ 0x)lambda函数:
[](){ std::cout << "lambda!" << std::endl; }
Run Code Online (Sandbox Code Playgroud)int main( )
{
functionProxy( Functor() );
functionProxy( function );
functionProxy( [](){ std::cout << "lambda!" << std::endl; } );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器将能够内联function中 …
我很难弄清楚如何对字符串向量的向量进行排序,这是测试代码。
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
int main(int argc, char** argv) {
std::vector <std::vector <std::string> > data_var;
std::vector <std::string> temp;
std::string str1 = "1,hello3,temp2";
std::string str2 = "2,hello2,temp1";
std::string str3 = "3,hello1,temp3";
boost::split(temp, str1, boost::is_any_of(","));
data_var.push_back(temp);
boost::split(temp, str2, boost::is_any_of(","));
data_var.push_back(temp);
boost::split(temp, str3, boost::is_any_of(","));
data_var.push_back(temp);
// sorting code here...
}
Run Code Online (Sandbox Code Playgroud)
提前致谢...