0
编辑:我明白我可以创建一个命名的函数来解决这个问题。我只想从你的大师那里学习一些神秘的C++模板语法。如何写std :: bind与构造函数
鉴于此设置(矢量保证是初始为空)
typedef vector<list<int>> V;
V v;
我想创建这样一个部分应用程序:
不幸的是,在我们的工作环境,我们不能使用lambda(使用gcc 4.4)。任何人都可以帮助我使用std::bind
写一个等效版本吗?
到目前为止,我想出了一些尝试(使用Visual Studio):
1.
auto f = bind<void (V::*)(const V::value_type&)>(&V::push_back, &v, list<int>(1, placeholders::_1));
错误
'<function-style-cast>': cannot convert from 'initializer list' to 'std::list<int,std::allocator<_Ty>>'
2.
auto f = bind<void (V::*)(const V::value_type&)>(&V::push_back, &v, list<int>::list(1, placeholders::_1));
与错误
'std::list<int,std::allocator<_Ty>>::list': none of the 10 overloads could convert all the argument types
3.
auto f = bind<void (V::*)(const V::value_type&)>(&V::push_back, &v, list<int> { placeholders::_1 });
错误
'initializing': cannot convert from 'initializer list' to 'std::list<int,std::allocator<_Ty>>'
4.
auto f = bind<void (V::*)(const V::value_type&)>(&V::push_back, &v, list<int> { (const int&) placeholders::_1 });
这个编译,而是由f(10)
创建的载体将具有与第一清单元素等于0,而不是10.它看起来像列表是默认创建的列表。
为什么它需要'std :: bind'?为什么不自己写一个本地课? –
有其他方式可以做部分申请吗? –
@crend lambdas只是匿名类对象。翻译是机械... – Yakk