Boost logo

Boost Users :

From: Cromwell Enage (sponage_at_[hidden])
Date: 2006-01-27 11:17:25


In one of my projects the header files contain code
like the following:

#ifndef BOOST_PARAMETER_RANDOM_EXAMPLE_HPP
#define BOOST_PARAMETER_RANDOM_EXAMPLE_HPP

#include <boost/type_traits/remove_const.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/parameter.hpp>

namespace example {

BOOST_PARAMETER_KEYWORD(tag, rng_engine)
BOOST_PARAMETER_KEYWORD(tag, min)
BOOST_PARAMETER_KEYWORD(tag, max)
BOOST_PARAMETER_KEYWORD(tag, factor)
BOOST_PARAMETER_KEYWORD(tag, addend)

struct foo_parameters
  : boost::parameter::parameters<
        boost::parameter::required<tag::rng_engine>
      , boost::parameter::required<tag::min>
      , boost::parameter::required<tag::max>
      , boost::parameter::optional<tag::factor>
      , boost::parameter::optional<tag::addend>
>
{
};

BOOST_PARAMETER_FUN(unsigned int, foo, 3, 5,
foo_parameters)
{
    typedef typename boost::remove_const<
                typename boost::parameter::binding<
                    Params
                  , tag::rng_engine
>::type
>::type
            RNGEngine;
    typedef boost::uniform_int<unsigned int>
            RNGDist;
    typedef boost::variate_generator<RNGEngine,
RNGDist>
            RNG;

    RNGEngine rng_engine = p[example::rng_engine];
    RNG rng(rng_engine, RNGDist(p[min], p[max]));

    return rng() * p[factor | 10] + p[addend | 5];
}
} // namespace test

#endif // BOOST_PARAMETER_RANDOM_EXAMPLE_HPP

The following snippet would then exemplify typical
user code:

#include <iostream>
#include <boost/ref.hpp>
#include <boost/random/mersenne_twister.hpp>
#include "boost_parameter_random_example.hpp"

int main()
{
    boost::mt19937 rng;
    std::cout << "Named: " << example::foo(
        example::rng_engine = rng
      , example::min = 12
      , example::max = 24
    ) << std::endl; // Ok
    std::cout << "Unnamed: ";
    std::cout << example::foo(rng, 12, 24); // error
    std::cout << std::endl;

    return 0;
}

MinGW reports:
'static const T&
boost::random::detail::ptr_helper<T&>::ref(const T&)
[with T = const boost::mt19937]' and 'static T&
boost::random::detail::ptr_helper<T&>::ref(T&) [with T
= const boost::mt19937]' cannot be overloaded

When I wrap boost::ref around rng, the program runs
fine.

I'm curious as to why I get this error only when
specifying positional arguments. Have I run afoul of
something fundamental, such as the forwarding problem?

                              Cromwell D. Enage

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.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