|
Boost Users : |
From: Ian McCulloch (ianmcc_at_[hidden])
Date: 2005-03-04 15:10:07
Matthias Kaeppler wrote:
> Ian McCulloch wrote:
>>>template< typename Operation >
>>>class indirecter_unary
>>> : public std::unary_function< typename
>>>boost::unary_traits<Operation>::argument_type,
>>
>>
>> Is this correct? You are advertising that your function has an
>> argument_type that is the same as Operation::argument_type. Don't you
>> want your argument_type to be a pointer?
>
> Hm yes, that is true. So let me correct this to:
>
> class indirecter_unary
> : public std::unary_function< typename
> boost::unary_traits<Operation>::argument_type*,
> typename boost::unary_traits<Operation>::result_type >
That will still cause problems with pointers to references.
>
> > In any event, since you need to
> > redefine argument_type and result_type yourself, there is no point
> > inheriting from std::unary_function.
> >
>
> Why? I thought those types are boost::unary_traits specific types? I
> thought I have to inherit from std::unary_function if I want to create
> what is called an "Adaptable Unary Function"?
No, you only need to provide the typedef's for argument_type and
result_type. std::unary_function is just a convenience to save typing.
But in your case, it only adds to the typing.
>
>>
>>>typename boost::unary_traits<Operation>::result_type >
>>>{
>>> typedef typename boost::unary_traits<Operation>::argument_type
>>> arg_type;
>>
>>
>> I think, the argument_type you are looking for is
>>
>> typedef typename boost::remove_reference<arg_type>::type*
>> argument_type;
>
> Thanks, that sounds reasonable.
>
>>
>>> typedef typename boost::unary_traits<Operation>::param_type
>>>param_type;
>>
>>
>> IIUC, param_type is supposed to be a type used to pass this function
>> object
>> as a parameter. ie, it should be something like indirecter_unary const&,
>> NOT the param_type of Operation.
>
> Yes, I know. That's how I used it: To pass objects of type Operation to
> the constructor of indirecter_unary.
Ok, I misunderstood the first time I read it.
>
>>
>>> typedef typename boost::unary_traits<Operation>::result_type
>>>result_type;
>>> typedef typename boost::unary_traits<Operation>::function_type
>>>function_type;
>>> function_type op_;
>>>public:
>>> explicit indirecter_unary( param_type op ): op_(op) {}
>>> result_type operator() (arg_type *arg) const {
>>
>> ^^^^^^^^^^
>> should be:
>> result_type operator()(argument_type arg) const {
>>
>>
>
> Should it? operator() is supposed to take pointers! Where would the
> indirection be if I would pass non-pointer types?
It does - from above:
>> I think, the argument_type you are looking for is
>>
>> typedef typename boost::remove_reference<arg_type>::type*
>> argument_type;
argument_type is a pointer type.
There is still a subtle problem here with what the argument_type should be
when Operator takes is argument by value. indirecter_unary should then
have an argument_type that is a pointer to const. One way to achieve that
would be to use remove_reference<add_const<arg_type>::type>::type* as the
argument_type.
Cheers,
Ian
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