Boost logo

Boost Users :

Subject: [Boost-users] [mem_fn] return type
From: Lowell McLinskey (lmclinskey_at_[hidden])
Date: 2009-08-31 23:33:35


I am having trouble understanding the return type of mem_fn. Is it possible
to create a vector of this type, analogous to how one can create a vector of
type mem_fun_t to hold the return values of mem_fun()? Here is an example
of what I'd like to do. Thanks in advance.
#include <vector>
#include <functional>
#include "boost/shared_ptr.hpp"
#include "boost/mem_fn.hpp"

class A
{
public:
    A(const int a) : a_(a) {}
    const int get() const {return a_;}
private:
    int a_;
};

int main(int argc, char** argv)
{
    // I can do this
    std::vector<std::const_mem_fun_t<const int, A> > v;
    v.push_back(std::mem_fun(&A::get));
    int i = v[0](new A(4));

    // and this
    boost::shared_ptr<A> p(new A(7));
    int j = boost::mem_fn(&A::get)(p);

    // but how do I do this?
    // std::vector< WHAT GOES HERE > w;
    // w.push_back(boost::mem_fn(&A::get));
    // int k = w[0](p);

    return 0;
}



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net