[Bimap][Function] Create a Boost.bimap of SDLKeys and Boost.functions
What is the correct syntax for creating a boost::bimap<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> >? (SDLKey is part of the SDL library. It is an enumeration. See here http://www.libsdl.org/cgi/docwiki.cgi/SDLKey) The code above does not compile, generating long cryptic template-related errors. Using an std::map<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> > works, however. I could use some help overcoming this obstacle.
Den 05-12-2011 06:44, John M skrev:
What is the correct syntax for creating a boost::bimap<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> >?
(SDLKey is part of the SDL library. It is an enumeration. See here http://www.libsdl.org/cgi/docwiki.cgi/SDLKey)
The code above does not compile, generating long cryptic template-related errors.
Using an std::map<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> > works, however.
I could use some help overcoming this obstacle.
Is boost::function<T> less-than comparable? This must be required for the reverse lookup when the function is used as key. -Thorsten
On Mon, Dec 5, 2011 at 12:44 AM, John M <b1tn3wsr34d3r@gmail.com> wrote:
What is the correct syntax for creating a boost::bimap<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> >?
The code above does not compile, generating long cryptic template-related errors.
Using an std::map<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> > works, however.
Yes, but does std::map<boost::function<void(boost::shared_ptr<Player>, bool)>, SDLKey> also compile? Both must be true to get bimap functionality.
On 12/05/2011 06:32 AM, Nat Linden wrote:
On Mon, Dec 5, 2011 at 12:44 AM, John M<b1tn3wsr34d3r@gmail.com> wrote:
What is the correct syntax for creating a boost::bimap<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> >?
The code above does not compile, generating long cryptic template-related errors.
Using an std::map<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> > works, however. Yes, but does std::map<boost::function<void(boost::shared_ptr<Player>, bool)>, SDLKey> also compile? Both must be true to get bimap functionality. Yes, std::map<boost::function<void(boost::shared_ptr<Player>, bool>, SDLKey> also compiles.
What is the correct syntax for creating a boost::bimap<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> >?
The code above does not compile, generating long cryptic template-related errors.
Using an std::map<SDLKey, boost::function<void(boost::shared_ptr<Player>, bool)> > works, however. Yes, but does std::map<boost::function<void(boost::shared_ptr<Player>, bool)>, SDLKey> also compile? Both must be true to get bimap functionality. Yes, std::map<boost::function<void(boost::shared_ptr<Player>, bool>, SDLKey> also compiles.
Did you try insert()-ing something into such a map? I think you'll find you get the same errors if you try that, as the ones you're getting with bimap. The bottom line is, boost::function is not LessThanComparable, so if you want to use it as the key of a map (or one of the keys of a bimap), you'll have to define your own comparison for it. Regards, Nate
participants (4)
-
John M
-
Nat Linden
-
Nathan Ridge
-
Thorsten Ottosen