Jump to content
  • Advertisement
Sign in to follow this  
scottdewald

boost::lambda & boost::function usage

This topic is 4275 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Using Boost 1.33.1 I'm trying to learn the boost::lambda library, so I created a few test cases. I wanted to create a std::set of a user defined type (with no operator<) defined. I did it two ways: stored the actual object and stored pointers to the object. I got it to compile both ways, but the const'ness of the boost::function arguments differed in the two. I don't understand why. EDIT: If I remove the const in Option 1 it breaks or if I add const in Option 2 it breaks.
struct Num
{
  Num(int v = 0) : val(v) {}
  int val;
};

// Option 1: storing objects
typedef boost::function<bool(const Num&,const Num&)> compare_t;
compare_t comp = boost::lambda::bind(&Num::val, boost::lambda::_1) < 
                 boost::lambda::bind(&Num::val, boost::lambda::_2);
std::set<Num,compare_t> myset(comp);
myset.insert(Num(3));


// Option 2: storing pointers
typedef boost::function<bool(Num*,Num*)> compare_t;
compare_t comp = boost::lambda::bind(&Num::val, boost::lambda::_1) < 
                 boost::lambda::bind(&Num::val, boost::lambda::_2);
std::set<Num*,compare_t> myset(comp);  
myset.insert(new Num(3));
[Edited by - scottdewald on November 8, 2006 11:28:40 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!