|
Boost Users : |
Subject: Re: [Boost-users] [fusion?] [Phoenix?] Calling arbitrary method with collection of args
From: Nat Goodspeed (nat_at_[hidden])
Date: 2010-03-19 11:25:08
Kim Kuen Tang wrote:
> From my opinion i 'll say that there is no ready-to-use function in boost.
Hmm! Further digging turned up boost::fusion::invoke(). The following
short program builds and runs as expected using Boost 1.39.0 with gcc 4.0.1.
The Fusion documentation says that support for boost::array is entirely
implemented with the non-intrusive Fusion extension mechanism. Hopefully
it won't be too hard to adapt the boost::array extension for our own
container. (I'm a bit surprised not to find existing support for
std::vector; presumably that's been done a few times by individuals.)
#include <iostream>
#include <boost/array.hpp>
#include <boost/fusion/include/array.hpp>
#include <boost/fusion/functional/invocation/invoke.hpp>
int somefunc(const std::string& a, const std::string& b)
{
std::cout << "somefunc('" << a << "', '" << b << "')\n";
return 17;
}
int main(int argc, char *argv[])
{
boost::array<std::string, 2> args = {{"first", "second"}};
int result = boost::fusion::invoke(somefunc, args);
std::cout << "somefunc() returned " << result << '\n';
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