[boost-users] [parameter] Error using positional arguments
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
Cromwell Enage
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?
That's precisely correct. When you use keyword arguments, the two overloads for T& T const& are cheap to generate. For positional arguments you get a 2^N explosion. http://www.boost.org/libs/parameter/doc/html/index.html#out-parameters -- Dave Abrahams Boost Consulting www.boost-consulting.com
Cromwell Enage
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?
I take it back; I'm pretty sure this has nothing to do with forwarding. On what line of *your code* does that error appear? I bet it actually appears in the random library. Thus, I bet this has nothing whatever to do with the parameter library. I suggest you reduce your problem to the minimal example that reproduces the problem. But first I suggest you make rng const in main and see what happens. I bet you get the same error. Remember, positional arguments are passed by const& unless you use ref(). -- Dave Abrahams Boost Consulting www.boost-consulting.com
--- David Abrahams wrote:
I take it back; I'm pretty sure this has nothing to do with forwarding. On what line of *your code* does that error appear?
The error appears on the line with the // error comment.
I suggest you reduce your problem to the minimal example that reproduces the problem.
I've replaced uniform_int and variate_generator with the old-school rng() * (min - max) + min, and replaced mt19937 with a trivial number generator whose () operator increments an internal counter before returning the counter's value. The error now states that calling rng() from within the function 'discards qualifiers', so I've indeed run into the forwarding problem. In my project, I cannot rearrange the parameters so that rng_engine is in the last position because a few of the other parameters accept defaults. However, because there are only a few such parameters, and because rng_engine is the only non-const parameter, writing the overloads myself (via Boost.Preprocessor and custom macros, of course) is a viable alternative. Thanks! Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Cromwell Enage
--- David Abrahams wrote:
I take it back; I'm pretty sure this has nothing to do with forwarding. On what line of *your code* does that error appear?
The error appears on the line with the // error comment.
The actual error, and not just some line of the instantiation
backtrace? That makes no sense to me, because the functions generated
by BOOST_PARAMETER_FUN take their arguments by const&. The error
should appear wherever you try to bind a non-const reference to the
resulting const lvalue. Aha:
typedef typename boost::remove_const<
^^^^^^^^^^^^
typename boost::parameter::binding<
Params
, tag::rng_engine
>::type
>::type
RNGEngine;
...
RNGEngine rng_engine = p[example::rng_engine];
According to
http://www.boost.org/libs/parameter/doc/html/reference.html#binding,
binding
--- David Abrahams wrote:
The actual error, and not just some line of the instantiation backtrace?
Sorry, that was part of the backtrace.
The error should appear wherever you try to bind a non-const reference to the resulting const lvalue.
That it did. I've uploaded the source files and error logs into a new "_Examples" directory in the Boost Vault, for posterity. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (2)
-
Cromwell Enage
-
David Abrahams