这两天被vs2010的std::tr1::bind郁闷了
std::tr1::function<bool(bool)> f4 =
std::tr1::bind(
std::logical_and<bool>(),
std::tr1::bind(std::logical_not<bool>(), std::tr1::placeholders::_1),
true);
std::tr1::bind(
std::logical_and<bool>(),
std::tr1::bind(std::logical_not<bool>(), std::tr1::placeholders::_1),
true);
想在vs2010里玩一玩function programming,却被郁闷了,又发现了一个别人发现过的bug
由 Microsoft 在 2009/8/7 18:33 发送
Hi,
Thanks for reporting this bug. Unfortunately, we have resolved it as Won't Fix for VC10. Our implementation is fragile when it comes to nested bind(), and we'll need to devote significant time to fixing it - time we don't have for VC10. (I can't promise anything, but I hope to be able to rewrite bind()'s implementation when we get variadic templates.)
The good news is that lambdas in VC10 supersede bind() in 99% of cases. Lambdas offer much more natural syntax (especially compared to nested bind()) and greater efficiency, since the optimizer can inline lambdas but has difficulty with bind()'s functors.
Here's an example that expresses your bind() functor as a lambda (doing something slightly different with it, but the functor has the same behavior):
C:\Temp>type meow.cpp
#include <algorithm>
#include <iostream>
#include <iterator>
#include <ostream>
#include <vector>
using namespace std;
int main() {
vector<int> v;
v.push_back(2);
v.push_back(4);
v.push_back(6);
v.push_back(8);
v.push_back(1);
v.push_back(3);
v.push_back(5);
v.push_back(7);
v.push_back(9);
vector<int> dest;
copy_if(v.begin(), v.end(), back_inserter(dest), [](int n) { return n >= 3 && n <= 8; });
for_each(dest.begin(), dest.end(), [](int n) { cout << n << " "; });
cout << endl;
}
C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp
C:\Temp>meow
4 6 8 3 5 7
Until you get VC10, remember that handwritten functors are always an alternative to using bind().
If you have any further questions, feel free to E-mail me at stl@microsoft.com .
Stephan T. Lavavej
Visual C++ Libraries Developer
Thanks for reporting this bug. Unfortunately, we have resolved it as Won't Fix for VC10. Our implementation is fragile when it comes to nested bind(), and we'll need to devote significant time to fixing it - time we don't have for VC10. (I can't promise anything, but I hope to be able to rewrite bind()'s implementation when we get variadic templates.)
The good news is that lambdas in VC10 supersede bind() in 99% of cases. Lambdas offer much more natural syntax (especially compared to nested bind()) and greater efficiency, since the optimizer can inline lambdas but has difficulty with bind()'s functors.
Here's an example that expresses your bind() functor as a lambda (doing something slightly different with it, but the functor has the same behavior):
C:\Temp>type meow.cpp
#include <algorithm>
#include <iostream>
#include <iterator>
#include <ostream>
#include <vector>
using namespace std;
int main() {
vector<int> v;
v.push_back(2);
v.push_back(4);
v.push_back(6);
v.push_back(8);
v.push_back(1);
v.push_back(3);
v.push_back(5);
v.push_back(7);
v.push_back(9);
vector<int> dest;
copy_if(v.begin(), v.end(), back_inserter(dest), [](int n) { return n >= 3 && n <= 8; });
for_each(dest.begin(), dest.end(), [](int n) { cout << n << " "; });
cout << endl;
}
C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp
C:\Temp>meow
4 6 8 3 5 7
Until you get VC10, remember that handwritten functors are always an alternative to using bind().
If you have any further questions, feel free to E-mail me at stl@microsoft.com .
Stephan T. Lavavej
Visual C++ Libraries Developer
由 Microsoft 在 2009/4/22 23:36 发送
Thanks for your feedback. We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Thank you,
Visual Studio Product Team
只好换boost或者lambda
posted on 2010-12-08 21:36 Michael Peng 阅读(3287) 评论(3) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库