Boost logo

Boost Users :

From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2006-03-02 05:58:04


David Abrahams wrote:
> "Johan Nilsson" <r.johan.nilsson_at_[hidden]> writes:
>
>

[snip]

>
>> It
>> should be possible (I think) to define a BOOST_PARAMETER_CTOR macro
>> that generate the ctor overloads and forwards to a setter method
>> instead of the other way around.
>
> It won't be general enough to initialize constant or reference
> members.

That's true, but for my current purposes it's good enough. I've defined my
own <foo>_PARAMETER_CTOR macro which takes care of it by delegation.

Ideally a BOOST_PARAMETER_CTOR macro should handle initialization of const
and reference members automagically, but if restrictions were stated clearly
in the docs I'd find an imperfect inclusion better than no one at all.

I personally very rarely use constant/reference class members, but
understand your
concerns. Perhaps a BOOST_PARAMETER_RESTRICTED_CTOR (or similarly
ugly-named) macro could be included in the library? Otherwise, maybe
mentioning
something about constructors in the faq would be a good idea?

Also, should the BOOST_PARAMETER_MEMFUN macro be documented?

>
>> 2. Is there a way of detecting whether an argument was passed using
>> position or name?
>
> Nope.

Ok.

>
>> Or, even better, is there a way of restricting the arguments to
>> only be passed by name using the parameters specification?
>
> Nope. Why do you want to do that?

I'd like to make sure that users have absolutely (well, almost) no
possibility of using arguments incorrectly. Consider the following (does not
compile):

---
#include <boost/parameter.hpp>
int foo(int index, int low_limit, int high_limit, int buffer_size)
{ ... }
BOOST_PARAMETER_KEYWORD(tag, index_p)
BOOST_PARAMETER_KEYWORD(tag, low_limit_p)
BOOST_PARAMETER_KEYWORD(tag, high_limit_p)
BOOST_PARAMETER_KEYWORD(tag, buffer_size_p)
struct wrap_foo_args
: boost::parameter::parameters<
    boost::parameter::optional<tag::index_p>,
    boost::parameter::optional<tag::low_limit_p>,
    boost::parameter::optional<tag::high_limit_p>,
    boost::parameter::optional<tag::buffer_size_p>
>
{};
BOOST_PARAMETER_FUN(int, wrap_foo, 0, 4, wrap_foo_args)
{
    return foo(p[index_p|-1], p[low_limit_p|0], p[high_limit_p|255],
p[buffer_size_p|1]);
}
int foo_with_fixed_high_and_buffer_size(int ndx, int low)
{
    return wrap_foo(low, ndx, high_limit_p = 1, buffer_size_p = 10); // ouch 
...
}
---
[snip remaining]
// Johan

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