Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-03-26 18:00:43


AMDG

Olaf Peter wrote:
> how can I make the snipped more generic in that way, that I can use it
> with different data members, e.g. as template argument the
> &actions::m_data::text data address. Then I could write e.g.
>
> set_generic<&actions::m_data::text, std::string> set_text;
>

template<typename T, T data::*mem_ptr>
struct set_generic
{
    explicit set_generic( actions& actions )
      : self( actions ) { }

    void operator()(const T& data) const {
        (self.m_data.*mem_ptr) = data;
    }

private:
    actions& self;
};

set_generic<std::string, &data::text> set_text;

In Christ,
Steven Watanabe


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