Boost logo

Boost Users :

From: StephQ (pelux_at_[hidden])
Date: 2007-11-20 08:27:37


David Abrahams <dave <at> boost-consulting.com> writes:

> Because Boost.Parameter is geared towards template type parameters, it
> might be easier to approach this problem by starting with a different
> interface for VariateSampler. Let's say:
>
> template <
> class TGenerator,
> class TDistribution,
> class Algorithm
> >
> struct _VariateSampler : Sampler<TDistribution>
> {
>
> };
>
> where Algorithm is required to be a function (object) callable with
> TDistribution and TGenerator arguments. You can easily map it onto
> the default you've specified using:
>
> template <class TDistribution, class TGenerator>
> struct default_algorithm
> {
> typename TDistribution::variate_t
> operator()(TDistribution const& d, TGenerator const& g) const
> {
> return d->sample_default(g);
> }
> };
>
> Default selection might be done through a simple metafunction:
>
> template <class T> struct is_PseudoRng;
>
> template <class U> struct is_PseudoRng<PseudoRng<U> >
> : boost::mpl::true_ {};
>
> ...
> mpl::if_<is_PseudoRng<some_generator>, default1, default2>::type
> ...
>
> HTH,
>

Thank you very much for your help.
However, I am a little confused about some details:

I suppose you meant using mpl::if_<...> to select one of the two following
funcion objects this way:

typedef mpl::if_<is_PseudoRng<TGenerator>,
default_pseudo<TDistribution,TGenerator>,
default_quasi<TGenerator,TGenerator> >::type myAlgorithm;
...
return myAlgorithm( ...,... );
 
template <class TDistribution, class TGenerator>
struct default_pseudo;

and

template <class TDistribution, class TGenerator>
struct default_quasi;

which calls respectively the member functions sample_pseudo and sample_quasi
(and these obviously different depending on the TDistribution they belong to).

But where should this selection happens?
Inside the class _VariateSampler, or in the implementation of the
boost::parameter technique for _VariateSampler?

And in any case, how can I override this selection, in case the user has invoked
the _VariateSampler specifying a particular function object Algorithm ?

Finally, would it be possible to extend this selection to multiple different
types mapping to multiple defaults?
I suppose you should use is_same_ or something like that, but I do not have much
experience with mpl. Could you suggest me some introductory references on this
particular topic (algorithms selection depending on complicated rules depending
on types).

Thank you again for your time.

Best Regards
StephQ

  


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