4 ms·
The point being made here is heavily obfuscated to my eye due to the seemingly needless use of std::invoke when working with the lambda cases (which, even if us
by saurik 9y ago
The point being made here is heavily obfuscated to my eye due to the seemingly needless use of std::invoke when working with the lambda cases (which, even if useful for some reason, is not needed to make the point of this article), but when I finally figured out what is being requested all I could think of is "that functionality of std::bind is horrific and surprising and despite going into this article thinking that of course bind solves a slightly different problem to lambdas in a more readable way, you have now convinced me that std::bind should be deprecated ASAP" (though as it came into existence in the same version of C++ as lambda functions, I mostly end up questioning why it ever existed).
Essentially, in order to provide something that sort of feels like lambda functions, but entirely in templates, the placeholder arguments do not end up locked to a single expression--instead of returning something semantically like a function, std::bind returns something that might be better described as a partial syntax tree that happens to be something you can call as a function, at which point it is only then wrapped up as a function and all subexpression parameters are bound to arguments--and so if you bind something and include in it a bound function, that function is not passed as a value like you would expect: its parameter is hoisted and it becomes a call expression in the new bound composite. The author likes this behavior for some reason, but I can't figure out why it would ever be considered to be a feature and it is trivially simulated with lambdas (while the opposite is not true).
- detaro 9y agoquotes from the article: > which is likely working by accident, rather than design. > At the time, it made some sense. But it makes reasoning about bind expressions difficult. Don’t do this. > Example of fail code Where do you get the idea the author likes it?! To me it reads more "it's stupid, but this edge case can't be trivially replaced and thus we can't just rip it out"
- comex 9y agoI don’t think it’s that the author likes the behavior, but that the author has in mind some rule where features can’t be deprecated unless it’s possible to write a purely mechanical migration tool. Not sure where that rule comes from or why it exists.
- Karellen 9y agoYeah, that's the biggest question that came to my mind too. Why can't you deprecate something that needs fixing up manually?
- sillysaurus3 9y agoC++ code bases are massive. It would be a nice rule to stick to, honestiy.
- CJefferson 9y agoThe idea is that if you want to deprecate something, you should tell people how to fix their code, so they can get working again with minimal work. However, even if it could be fixed up, I don't think it will get deprecated. C++ is (rightly in my mind) extremely cautious about removing things -- it's easy to ignore std::bind, it's just a library function. On the other hand, I'd be annoyed if my perfectly working C++ code base I've been building over 10 years just broke one day. One thing I love about C++ and C is that I can leave my code for 5 or even 10 years, come back, and expect it to still work just fine.
- lklklkj2342487 9y agoIsn't it what the standard compiler switch is for? For instance if your codebase builds fine with -std=c++17 and std::bind would have been removed in C++20, your code base would still compile fine because the compiler would figure it out.
- CJefferson 9y agoUnfortunately, that's hard in C++ because lots of code often ends up in headers because templated code must be in headers, and so then you can't link a C++17 and a C++20 library together (for example). Also, it's nice to be able to use new features without having to go and re-write lots of existing code. It does however fix the basic problem of a complete program. Hopefully, one day modules will fix this and we'll be able to link modules from different versions of C++ together, but I'm not holding my breath.
- slezyr 9y ago> you have now convinced me that std::bind should be deprecated ASAP Once made a mistake using std::bind and got 500 lines of errors.
- prance 9y ago> instead of returning something semantically like a function, std::bind returns something that might be better described as a partial syntax tree that happens to be something you can call as a function Indeed. std::bind seems to work more like a Lisp-ish macro than a function in this regard.