|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-03-04 23:40:46
"Johan Nilsson" <r.johan.nilsson_at_[hidden]> writes:
> 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.
If you propose a patch against the current CVS, we'll consider it for
boost 1.35 (1.34 is in feature freeze).
> 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?
I don't think there's a real need to uglify. Usually ctors are pretty
simple anyway; I think this macro should just generate the ctor
overloads directly instead of doing any forwarding. Daniel, what do
you think about that?
Note, however, that we have a new, much more powerful, macro system
for Boost.Parameter. See
http://www.boost-consulting.com/boost/libs/parameter/test/preprocessor.cpp
Whatever you do should be compatible with that.
> Otherwise, maybe mentioning something about constructors in the faq
> would be a good idea?
Sure, good idea. Patches would be very welcome.
> Also, should the BOOST_PARAMETER_MEMFUN macro be documented?
We're going to document the new macro system.
>>> 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
> ...
> }
I think it's awfully nanny-ish to want to do that, but adding such a
feature *should* be fairly easy.
-- Dave Abrahams Boost Consulting www.boost-consulting.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