on Wed Sep 10 2008, e r
hi,
here's what i'd like to do
A]
hpp:
struct my{ template<typename ArgPack> my(const ArgPack& args):n_(args[tag::n]),k_(args[tag::k]){} }
struct argpack{ arglist<???> operator()(const string& str){???} }
cpp:
string str("n=2; k=1");
my(argpack(str));
In words,I'm looking to construct an ArgPack from a string, what's the appropriate library for this?
Well, unless the types of all your arguments are the same *and* you have a limited set of parameter names, all known at compile time, Boost.Parameter can not help at all... and even if you meet all those conditions, using Boost.Parameter would probably be more trouble than it is worth. The problem is that Boost.Parameter establishes an association between keywords and argument values at compile time, and your strings have to be parsed at runtime.
Does it seem like I should invest in Boost Spirit?
Almost any of Boost's text processing libraries might be useful to you. In your case, it might be easiest to build something on Boost.Regex or Boost.XPressive, or even tokenizer, since the job you're doing is so simple.
The above is a simplified version of what i really need, which is, potentially, 1) having to construct a large number of objects (to be pushed at the back of a container) 2) each object taking a large number arguments (not just n and k as above) 3) each object an instance of one of a set of classes (my0,my1,my2,...,myN) each with its specific argument tags (keywords).
So I'd like to put all these arguments in a file, each line corresponding to an object, rather than have a messy cpp file.
Well, if you're willing to compile that file as C++, you could go back to using Boost.Parameter... ;-) -- Dave Abrahams BoostPro Computing http://www.boostpro.com