boost-lambda

c++ boost lambda libraries

What might be the best way to start programming using boost lambda libraries. ...

Boost phoenix or lambda library problem: removing elements from a std::vector.

I recently ran into a problem that I thought boost::lambda or boost::phoenix could help be solve, but I was not able to get the syntax right and so I did it another way. What I wanted to do was remove all the elements in "strings" that were less than a certain length and not in another container. This is my first try: std::vector<std::...

boost lambda or phoenix problem: using std::for_each to operate on each element of a container

I ran into a problem while cleaning up some old code. This is the function: uint32_t ADT::get_connectivity_data( std::vector< std::vector<uint8_t> > &output ) { output.resize(chunks.size()); for(chunk_vec_t::iterator it = chunks.begin(); it < chunks.end(); ++it) { uint32_t success = (*it)->get_connectivity_data(output[it-chunks.beg...

Boost.Lambda: Insert into a different data structure

I have a vector that I want to insert into a set. This is one of three different calls (the other two are more complex, involving boost::lambda::if_()), but solving this simple case will help me solve the others. std::vector<std::string> s_vector; std::set<std::string> s_set; std::for_each(s_vector.begin(), s_vector.end(), s_set.insert(...

Boost lambda bewilderment

Why is callback called once only? bool callback() { static bool res = false; res = !res; return res; } int main(int argc, char* argv[]) { vector<int> x(10); bool result=false; for_each(x.begin(),x.end(),var(result)=var(result)||bind(callback)); return 0; } ...

boost lambda collection size evaluation

I have a function of the form: void DoSomething(const boost::function<bool ()>& condition, other stuff); This function does some work and returns only when the condition is true. The condition has been expressed as a functor argument because I want to supply different conditions at different call sites. Now, this is fairly straightf...

Problem nesting boost::lambda::bind-s

I have a generic function: void ImageAlbum::ExpressButtonPressed( boost::function< void ( thumb::PhotoPrintThumbnail*, thumb::PhotoPrintFormat, thumb::PhotoPrintQuantity ) > memberToCall ) { ... BOOST_FOREACH(thumb::PhotoPrintThumbnail *pThumbnail, m_thumbs.GetSelected()) { memberToCall( ...

using boost::lambda_ to compress whitespaces in a string

Hi, I am using boost::lambda to remove subsequent whitespaces in a string, leaving only one space. I tried this program. #include <algorithm> #include <iostream> #include <string> #include <boost/lambda/lambda.hpp> int main() { std::string s = "str str st st sss"; //s.erase( std::unique(s.begin(), s.end(), (boost::lamb...

C++: how to use std::less<int> with boost::bind and boost::lambda?

I am trying to lean boost::bind, boost::lambda libraries and how they can be used with STL algorithms. Suppose I have vector of int-string pairs which is sorted by int key. Then a place to insert a new pair while keeping the vector sorted can be found as follows: std::vector<std::pair<int, string> > entries; ... int k = ...; // Let's i...

Usage of boost lambdas

I am new to boost and trying to write some simple programs to understand it. Here in the following piece of code I am trying to fill an array with random numbers. Here is my code: using namespace boost::lambda; srand(time(NULL)); boost::array<int,100> a; std::for_each(a.begin(), a.end(), _1=rand()); But it looks like r...

Calling a member function using boost::lambda

I am learning the boost::lambda library and for that I wrote this sample code to convert an vector<A> into vector<int> by extracting the value from A object. class A { public: A(int n) : m_n(n){} int get() const {return m_n;} private: int m_n; }; int _tmain(int argc, _TCHAR* argv[]) { using namespace boost::lambda; ...

How do I create a simple boost::lambda function?

Hi, I'm trying to create a simple function that makes a simple test and return true or false. myfunct = (_3 < someArray[i]); When I do this, I get this error : error: no match for 'operator<' in '<unnamed>::_1 < depths[i]' What I hope is get something equivalent to this bool myFunct(unsigned int a, unsigned int b, unsigned int c, ...

What is wrong with this boost::lambda use?

Why is this boost::lambda expression not working? boost::function<bool (boost::uint64_t, boost::uint64_t&, unsigned int, float)> myFunct = boost::lambda::_3 < 1; I get theses compilation errors, that won't probably help, because they are really cryptic. || In file included from /usr/include/boost/function/detail/maybe_include.hpp:33,...

boost::function and boost::bind are cool, but what is really cool about boost::lambda ?

On Page 175 Paragraph 1 of Effective C++ Meyers has this to say about generalized functors and binding: I find what tr1::function lets you do so amazing, it makes me tingle all over. If you're not tingling , it may be because you're staring at the definition of ... and wondering what's going on with the .... And I agree w...

Trying to use boost lambda, but my code won't compile

Hi, I am trying to use boost lambda to avoid having to write trivial functors. For example, I want to use the lambda to access a member of a struct or call a method of a class, eg: #include <vector> #include <utility> #include <algorithm> #include <boost/lambda/lambda.hpp> using namespace std; using namespace boost::lambda; vector< pa...

boost lambda::bind return type selection

I would like to call a member through lambda::bind. Unfortunately I have got two members with the same name but different return types. Is there a way to help the lambda::bind to deduce the right return type for a member function call? (bind works fine with explicit return type deduction) #include <vector> #include <iostream> #include <...

Boost lambda: Invoke method on object

I'm looking at boost::lambda as a way to to make a generic algorithm that can work with any "getter" method of any class. The algorithm is used to detect duplicate values of a property, and I would like for it to work for any property of any class. In C#, I would do something like this: class Dummy { public String GetId() ... ...

boost::lambda bind expressions can't get bind to string's empty() to work

Hi, I am trying to get the below code snippet to compile. But it fails with: error C2665: 'boost::lambda::function_adaptor::apply' : none of the 8 overloads could convert all the argument types. Sepcifying the return type when calling bind does not help. Any idea what I am doing wrong? Thanks. #include <boost/lambda/lambda.hpp> #in...

Correct use of boost lambda

Consider the following piece of C++0x code: a_signal.connect([](int i) { if(boost::any_cast<std::string>(_buffer[i]) == "foo") { base_class<>* an_object = new derived_class(); an_object->a_method(_buffer[i]); }}); How would it correctly look in Boost Lambda (since this C++0x feature can't be used in GCC 4.4 yet)? ...

C++/boost generator module, feedback/critic please

hello. I wrote this generator, and I think to submit to boost people. Can you give me some feedback about it? It basically allows to collapse multidimensional loops to flat multi-index queue. Loop can be boost lambda expressions. Main reason for doing this is to make parallel loops easier and separate algorithm from controlling struct...