Ticket #7441: t1.cpp

File t1.cpp, 995 bytes (added by Mike Cowperthwaite <michael.cowperthwaite@…>, 10 years ago)
Line 
1#include <boost/system/system_error.hpp>
2#define TR1
3#if defined(TR1)
4#include <functional> // MSVS 2008: std::tr1::function<> and std::tr1::bind<>, among others
5#else
6#include <boost/function.hpp>
7#endif
8#include <boost/bind.hpp>
9
10using boost::system::error_code;
11#if defined(TR1)
12using std::tr1::function;
13#else
14using boost::function;
15#endif
16
17using boost::bind; // <== notice this
18
19// declare global from elsewhere
20void AddErrorSink(function<void(error_code)> fn);
21
22class D
23{
24public:
25 typedef function<void(void)> Action;
26 void AddErrorAction(Action &a);
27
28protected:
29 void exec_actor(Action &a, error_code ec);
30};
31
32
33void D::AddErrorAction(Action &a)
34{
35 // when TR1 is defined for compilation, this line fails:
36 // >> error C2668: 'boost::bind' : ambiguous call to overloaded function
37 // ambiguity shown between boost::bind and std::tr1::bind
38 // can be overcome by qualifying call ("boost::bind")
39 AddErrorSink(bind(&D::exec_actor, this, a, _1));
40}