Trey Jackson wrote:
>  >template <class DataType, class FunctionType = 
> boost::function1<void,
>  >DataType> >
>  >class work_crew {
>  >  std::list<DataType>   queue_;
>  >  FunctionType          engine_;
>  >public:
>  >  work_crew(FunctionType const& tocall);
>  >  void add(DataType d) { queue_.push_front(d); };
>  >  void dowork()
>  >  { 
>  >    typedef typename std::list<DataType>::iterator iterator_t;
>  >    for (iterator_t iter = queue_.begin(); iter != 
> queue_.end(); ++iter)
>  >       tuples::apply(this->engine_, *iter); // here
>  >  };
>  >};
> 
> Question: does the above work even if my work_crew is still the
> vanilla:
> 
>     work_crew< int, boost::function<void, int> > vanillaCrew(....);
> 
> or would I need
> 
>     work_crew< tuples::tuple<int>, boost::function<void, int> 
> > closeToVanillaCrew(....);
> 

Not as I wrote it. It's a relatively easy to achieve, though -

  void dowork()
  { 
    this->do_work(is_tuple<DataType>());
  };

  void dowork(mpl::false_c)
  { 
    typedef typename std::list<DataType>::iterator iterator_t;
    for (iterator_t iter = queue_.begin(); iter != queue_.end(); ++iter)
       this->engine_(*iter);
  }

  void dowork(mpl::true_c)
  { 
    typedef typename std::list<DataType>::iterator iterator_t;
    for (iterator_t iter = queue_.begin(); iter != queue_.end(); ++iter)
       tuples::apply(this->engine_, *iter);
  };

... except that you would have to implement 'is_tuple' yourself. Not a big
deal, but definitely an inconvenience; should be in the library.

> 
> - I ask b/c of the 'tuples::apply(...)' portion.
> At first glance, it's not clear that
> 
>    int i;
>    tuples::apply(this->engine_, i)
> 
> would not work (b/c i is not a tuple).

It wouldn't, as it is. It's an interesting question if it should. IMO a
separate function, let's say 'as_tuple' (analogous to MPL's 'as_sequence')
would be a cleaner solution here, 

    int i;
    tuples::apply(this->engine_, tuples::as_tuple(i)); // OK

    tuple<int> ti;
    tuples::apply(this->engine_, tuples::as_tuple(ti)); // OK, too

since there are other places there one would like to have this machinery. Of
course, 'tuples::apply' still can do this 'as_tuple' call internally. Right
now I don't have a strong opinion whether it should or not.

Aleksey
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to