boost::bind/boost::function and fast delegates
hello all: We have a project we're working on that will be distributed, and I didn't want to have to set boost as a dependency if we're only using boost::bind and boost::function. Given this, I had a couple steps. First I thought I could possibly just copy out the code and modify it a bit, but it uses a ton of boost::preprocessor, so that'd require copying that out too. I'd rather not imbed half of boost in the project. My other solution (and one I really like) was to write my own delegates. I set to work on this and it's coming out good, but I have a couple questions. I know you can assign function pointers to boost::function objects, though I've always done it through bind. I'm curious how this works though: I have a normal function pointer set up and working right now, but how does boost::function take other pointers (say to static methods)? Also I'm curious what boost::bind generates. I'd like to create my own version since I love using it to pass in arbitrary values/using placeholders, but the boost::function has to be able to take a newly constructed function object and bind to that from what I understand. The new function object somehow has it's arguments stored on the object so that the () operator can just pass those in. Any help here would be appreciated. Thanks, -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.
On 1/21/2013 2:26 PM, Steve Lorimer wrote:
we're only using boost::bind and boost::function.
At the risk of stating the obvious, why not use std::bind and std::function?
They are part of the current standard library, introduced in c++11
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
But not supported by vs 2010 (or 2008), which is what half of the team still uses. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.
On 21/01/2013 10:58 PM, Littlefield, Tyler wrote:
On 1/21/2013 2:26 PM, Steve Lorimer wrote:
we're only using boost::bind and boost::function.
At the risk of stating the obvious, why not use std::bind and std::function?
They are part of the current standard library, introduced in c++11
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
But not supported by vs 2010 (or 2008), which is what half of the team still uses.
As a business decision, you might be better off doing a team upgrade to VS 2012. The Professional price is around $700 a seat, which is about the actual organisational cost of an intermediate developer for a day. You'll get std::bind and std::function as part of that. Contrast that one-time cost (which you'll pay eventually anyway) against the cost of your time to do the custom delegate development, plus maintenance cost over the life of your code. Two weeks of your time on custom delegates would pay for at least ten licenses. Damien
From: Littlefield, Tyler
On 1/21/2013 2:26 PM, Steve Lorimer wrote: > we're only using boost::bind and boost::function. At the risk of stating the obvious, why not use std::bind and std::function? They are part of the current standard library, introduced in c++11 But not supported by vs 2010 (or 2008), which is what half of the team still uses.
According to MSDN, VS2008 and VS2010 have std::tr1::bind and std::tr1::function. Best regards, RK
On 1/22/2013 4:33 AM, Robert Kawulak wrote:
From: Littlefield, Tyler
On 1/21/2013 2:26 PM, Steve Lorimer wrote:
we're only using boost::bind and boost::function. At the risk of stating the obvious, why not use std::bind and std::function? They are part of the current standard library, introduced in c++11 But not supported by vs 2010 (or 2008), which is what half of the team still uses.
According to MSDN, VS2008 and VS2010 have std::tr1::bind and std::tr1::function.
Actually starting with VS2010 bind and function were moved into the standard namespace and are now std::bind and std::function. For that matter I think all of what was originally std::tr1 is now just in the std namespace. -- Bill
Hello Tyler,
please see my answer below.
On Mon, Jan 21, 2013 at 8:22 PM, Littlefield, Tyler
hello all: We have a project we're working on that will be distributed, and I didn't want to have to set boost as a dependency if we're only using boost::bind and boost::function. Given this, I had a couple steps. First I thought I could possibly just copy out the code and modify it a bit, but it uses a ton of boost::preprocessor, so that'd require copying that out too. I'd rather not imbed half of boost in the project. There is a tool, which you can try: BCP http://www.boost.org/doc/libs/1_52_0/tools/bcp/doc/html/index.html. This tool can extract a particular library and all its dependencies out of boost.
My other solution (and one I really like) was to write my own delegates. Don't do that ;) You will end up in a real mess... boost::bind, boost::function & co have all that preprocessor macros etc. not because developers were that eager to bloat the code, but because they needed them to generate overloads for all kinds of variations like pointer to member, global function etc. and "any possible" number of params (I think 10 or so): function with one param, with two params with 3 params and so on. Finally each of these functions can be non-const, const or volatile or const-volatile. Than you have arguments (const, volatile, non-const params being passed as pointer, reference or value). Doing that manually is tedious. Sometimes its fine to not distinguish the parameter constness, but sometimes you need to and that depends on the use case.
I set to work on this and it's coming out good, but I have a couple questions. I know you can assign function pointers to boost::function objects, though I've always done it through bind. I'm curious how this works though: I have a normal function pointer set up and working right now, but how does boost::function take other pointers (say to static methods)? Also I'm curious what boost::bind generates. I'd like to create my own version since I love using it to pass in arbitrary values/using placeholders, but the boost::function has to be able to take a newly constructed function object and bind to that from what I understand. The new function object somehow has it's arguments stored on the object so that the () operator can just pass those in. Any help here would be appreciated.
If you can afford take C++11. It has adopted bind, function (and much more like lambdas integrated into the language). Than your users are going to depend on STL only. If you still have a desire to write you own function delegates, take a look at the bugs which were fixed in these libs since their inception. You will have to deal with the same amount of them. And finally, these libs are documented and really well tested with different compilers and are portable! They also work around different compiler defects in regards to C++ standard. And if you still wish to write such a lib(s) take a look at this article: http://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-the-Fa...
Thanks,
-- Take care, Ty
Regards, Ovanes
participants (6)
-
Bill Buklis
-
Damien Hocking
-
Littlefield, Tyler
-
Ovanes Markarian
-
Robert Kawulak
-
Steve Lorimer