boost-lambda

Post callbacks to a task queue using boost::bind

血红的双手。 提交于 2021-01-27 10:41:53
问题 Suppose I have a function called subscribe() that takes a callback handler, which will be called when the event is triggered. Now, I have another version, called subscribe2() . Everything is the same except that, when triggered, it needs to post it to an event queue. It is implemented using the original subscribe() , with a helper funciton called helper() . All it does is to bind the original handler and whatever additional arguments into a functor, and call postToEventQueue() . Now, I wonder

Post callbacks to a task queue using boost::bind

倾然丶 夕夏残阳落幕 提交于 2021-01-27 10:40:35
问题 Suppose I have a function called subscribe() that takes a callback handler, which will be called when the event is triggered. Now, I have another version, called subscribe2() . Everything is the same except that, when triggered, it needs to post it to an event queue. It is implemented using the original subscribe() , with a helper funciton called helper() . All it does is to bind the original handler and whatever additional arguments into a functor, and call postToEventQueue() . Now, I wonder

Boost lambda example

放肆的年华 提交于 2019-12-24 03:35:16
问题 I have a map created as a part of solution enum Opcode { OpFoo, OpBar, OpQux, }; // this should be a pure virtual ("abstract") base class class Operation { // ... }; class OperationFoo: public Operation { // this should be a non-abstract derived class }; class OperationBar: public Operation { // this should be a non-abstract derived class too }; std::unordered_map<Opcode, std::function<Operation *()>> factory { { OpFoo, []() { return new OperationFoo; } } { OpBar, []() { return new

Boost Phoenix (or Boost Lambda) - taking a pointer lazily

青春壹個敷衍的年華 提交于 2019-12-23 19:43:03
问题 Is there a way of taking a pointer of a lazy phoenix value / ref ? If so how ? 回答1: Phoenix placeholders overload operator&() , therefore a simple &_1 should do the trick (see Phoenix docs here). 来源: https://stackoverflow.com/questions/5211894/boost-phoenix-or-boost-lambda-taking-a-pointer-lazily

What is the difference between boost::bind and boost::lambda::bind?

让人想犯罪 __ 提交于 2019-12-21 04:57:20
问题 I can see that there are two different bind libraries for Boost, one "standalone", that can be used by including boost/bind.hpp , and another by including boost/lambda/bind.hpp . What's the difference between these two? 回答1: Have a look at the explanation here: http://boost.org/doc/libs/1_46_0/doc/html/lambda/s08.html#id2143701 They have overlapping functionality but with semantic differences, they can't be used interleaved. 来源: https://stackoverflow.com/questions/5202974/what-is-the

boost::lambda std::map

不羁的心 提交于 2019-12-13 05:50:01
问题 I want to simplify my code by using boost::lambda. Here is my code: // Declare container: typedef std::map< PageId, Page* > Pages; Pages m_pages; // For serialization: template < class DataType > TPair< DataType > makePair( const std::string& identification, const DataType& dataType ) { return TPair< DataType >( identification, dataType ); } #define SERILIZE_CLASS( _value ) ::Tools::Serilizer::makePair< ::Tools::Serilizer::Serilizable >( EXTRACT_NAME( _value ), _value ) // This does work and

Boost.Lambda - dereference placeholder

无人久伴 提交于 2019-12-13 04:07:01
问题 Is there a way to dereference a placeholder inside lambda expression ? boost::function<int(MyClass*)> f = _1->myMethod(); f(myObject); I know I can make a binding: boost::function<int(MyClass*)> f = boost::bind(&MyClass::myMethod, _1); , but I want to build more complex expression, with if statements and so on. 回答1: In theory this should work: struct Foo { int bla() { return 2; } }; boost::function<int(Foo*)> func = (_1 ->* &Foo::bla); There is an old discussion featuring various work-arounds

using boost lambda with compound expressions

雨燕双飞 提交于 2019-12-11 17:39:17
问题 I have a Visual Studio 2008 C++03 application where I would like to use boost::lambda to perform this action: enum { fooflag = 0x00000001; } bool IsFooFlagActive( DWORD flags ) { return ( flags & fooflag ) != 0; } Unfortunately, this doesn't work: namespace bl = boost::lambda; bool is_foo_flag_active = ( ( bl::_1 & fooflag ) != 0 )( 0x00000001 ); What's the correct way to get boost::lambda to perform compound expressions? Do I need to bind the != operator? Thanks 回答1: I don't know what the

What is wrong with this boost::lambda::bind usage?

天涯浪子 提交于 2019-12-11 00:55:24
问题 Is there something wrong in this code? I keep getting compilation errors. Basically I want to connect a void returning function to a signal which has a non void return type. Boost version: Release 1.46.1 #include <boost/signals2.hpp> #include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> using namespace boost::signals2; void func() { printf("Func called!"); } main() { signal<int(int)> sig; sig.connect( (boost::lambda::bind(func), 1) ); } I get the following error while compiling:

another copy algorithm

*爱你&永不变心* 提交于 2019-12-10 03:19:23
问题 I have two vectors. vector<Object> objects; vector<string> names; These two vectors are populated and have the same size. I need some algorithm which does assignment to the object variable. It could be using boost::lambda. Let's say: some_algoritm(objects.begin(), objects.end(), names.begin(), bind(&Object::Name, _1) = _2); Any suggestion? 回答1: I can't think of a std:: algorithm for this. But, you can always write your own: template < class It1, class It2, class Operator > It2 zip_for_each (