2012年3月9日

C++11: 使用 lambda 创建模板类 的 对象

摘要: C++ 中 lambda 可以直接传递给模板函数如 std::sort, 但无法传给模板类如 std::map,但是,使用一点小技巧,可以使用 lambda 创建模板类的对象,省了很多麻烦的 coding。这里给出一个示例:#include #include templatestd::map make_map(Compare comp) { return std::map(comp);}int main() { auto m = make_map([](int x, int y) { return x %d\n", x.first, x.second); } retur... 阅读全文

posted @ 2012-03-09 11:46 能发波 阅读(505) 评论(0) 推荐(0)

导航