Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2005-12-10 09:13:37


"Neil Hunt" <boost_at_[hidden]> writes:

> I guess the main thrust of the question is "Does the parameters library
> support runtime enumeration?"

Not directly, but it seems like something we (sh/c)ould support,
probably by making ArgumentPacks conforming Fusion sequences so you
could use boost/spirit/fusion/algorithm/for_each.hpp to enumerate them.
The problem is that I don't have expertise with Fusion-1 and AFAIK it's not
fully documented. Specifically, I don't know how to make a conforming
Fusion sequence. Maybe Joel can help. Joel?

> or should I be looking at MPL?

Wouldn't help you, at least not directly. Well, here's one thing you
could do (ALL_CAPS should be reserved for macros, so I'm going with
lower_case):

  // untested
  BOOST_PARAMETER_KEYWORD(tag, person_window)
  BOOST_PARAMETER_KEYWORD(tag, address_window)
  BOOST_PARAMETER_KEYWORD(tag, employer_window)

  typedef mpl::vector<
     tag::person_window, tag::address_window, tag::employer_window
>
  all_windows;

  template <class ArgumentPack, class F>
  struct process_arg
  {
      process_arg(ArgumentPack args, F f) : args(args), f(f) {}

      template <class Keyword>
      void operator()(Keyword k) const
      {
          f(k, args[k]);
      }

   private:
      ArgumentPack const& args;
      F const& f;
  };

  template <class Keywords, class ArgumentPack, class F>
  for_each_arg(ArgumentPack const& args, F const& f)
  {
      mpl::for_each<Keywords>( process_arg<ArgumentPack,F>(args,f) );
  }

  Now you can for_each_arg(args, f) where f is some binary function
  you'd like to be applied to each argument. The first parameter is
  the keyword (just in case you need it) and the second one is the
  original argument passed.

This won't cope well with missing default arguments, so it seems to me
making our ArgumentPacks conforming fusion sequences is really the way
to go.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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