Boost logo

Boost :

From: Cromwell Enage (sponage_at_[hidden])
Date: 2005-05-27 17:24:58


A new user may naively expect Boost.Bind to accept
function templates just as it does ordinary functions.
 For example:

    std::map<Vertex,Vertex> vertex_map;
    boost::prim_minimum_spanning_tree(
        graph
      , boost::make_associative_property_map(
            vertex_map
        )
    );

works just as well as

    std::map<Vertex,Vertex> vertex_map;
    boost::prim_minimum_spanning_tree(
        graph
      , boost::make_associative_property_map<
            std::map<Vertex,Vertex>
>(vertex_map)
    );

However, when converting
boost::make_associative_property_map to a function
object, the following code:

    std::map<Vertex,Vertex> vertex_map;
    boost::bind(
        boost_make_associative_property_map
      , vertex_map
    ) map_maker;
    boost::prim_minimum_spanning_tree(
        graph
      , map_maker()
    );

will not compile. The correct code is:

    std::map<Vertex,Vertex> vertex_map;
    boost::bind(
        boost_make_associative_property_map<
            std::map<Vertex,Vertex>
>
      , vertex_map
    ) map_maker;
    boost::prim_minimum_spanning_tree(
        graph
      , map_maker()
    );

It took me quite a while to realize a mistake I made
like this. I'm sure others will commit the same sort
of mistake as well. Would it be too much for the
Boost.Bind documentation to provide a note of caution
with regard to function templates?

                              Cromwell D. Enage

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk