Boost logo

Boost Users :

Subject: Re: [Boost-users] Member functions on boost::variant?
From: Igor R (boost.lists_at_[hidden])
Date: 2009-09-06 05:08:33


> Is there a nice way of calling a member function on a boost::variant (where
> I know said member function is implemented by all the types in the variant)?

if the member function has signature:
retval func();

then you can call it using the following visitor:

// warning: untested
struct call_func : static_visitor<retval>
{
  template<class T> result_type operator()(T t) const
  {
    return t.func();
  }
};

You can also pass parameters to the visitor constructor, then forward
them to the func().


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