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
#include
#include
#include
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::requiredtag::rng_engine
, boost::parameter::requiredtag::min
, boost::parameter::requiredtag::max
, boost::parameter::optionaltag::factor
, boost::parameter::optionaltag::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
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
#include
#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::ref(const T&)
[with T = const boost::mt19937]' and 'static T&
boost::random::detail::ptr_helper::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