Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-06-23 07:32:41


On Fri, June 23, 2006 04:45, Gottlob Frege wrote:
>> From: "Ovanes Markarian" <om_boost_at_[hidden]>
>>
>> Hello all,
>>
>> I am trying to specialize boost::is_pointer so, that it can determine if a
>> type is a pointer
>> wrapper (shared_ptr, auto_ptr, weak_ptr).
>>
>> Does anybody has ideas how this can be done? May be it would be possible
>> to handle if e.g. one can
>> determine if a class/struct has some typedef inside:
>>
>>
>>
> You can make a template to detect typedefs - I wrote a has_value_type<T> for
> value_type. In my case I needed to know if the underlying type was char or
> wchar_t, so I ended up with a recursive thing that would even resolve things
> like a 'list of vectors of strings', etc.
>
>
>>
>> Somehow I am not certain if I am on the right path. My problem is that I
>> have a variant container
>> type with different types. One could access a value using -> operator. The
>> operator returns the
>> pointer to the value. But if this value is a pointer (that can be
>> determined by boost::is_pointer
>> type trait) it should return the pointer and not pointer to pointer value.
>> Now what happens if I
>> store shared_ptr or any other type which overload -> operator? This will
>> result in compiler error,
>> because the compiler tries to access member of the pointer to pointer and
>> not of the pointer
>> instance.
>
>
>
> You can also write a has_specific_member_function<T>, and thus I suspect you
> could also do it for operator->(). I think it depends on whether you can
> take a member function pointer to an operator function.
>
>
> google for has_foo, or try
> http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/a69f4423b407b1ab/0814dfec14027822?lnk=st&q=has_foo&rnum=1#0814dfec14027822
>
>
>
> Is there may be a way to determine if the member access operator is
>> overloaded? What if ->
>> operator is defined in the base? And what if child class inherits base as
>> protected or private?
>
>
> Haven't tried any variations on public/protected/private - I suspect that
> you need to have a template that checks publicly, then another that checks
> for protected (I suspect that version of has_arrow_op<T> would probably need
> to derive from T) and I doubt you could tell the difference between a class
> that doesn't have ->, and a class that has a private ->. But I doubt you
> would want to know - if it doesn't have a callable ->, then you should
> probably act like it doesn't have one at all - ie it doesn't want you to
> think of it as a pointer.
>
> The other solution would be to force every user to write a specialized class
>> is_pointer for every
>> type stored in variant, but this would be not so nice.
>>
>>
>> With Kind Regards,
>>
>> Ovanes Markarian
>
>
>
> Tony
>

Thanks a lot for your answer. I think the most general solution would be to look up for the member
access operator (->). Unfortunately to do this lookup I have to know which type this operator
returns ;)

Now I am not certain if I can use result_of metafunction to calculate the result type. I think
this function calculates the result type of expressions as:
int(char, int), which define a result type. In my case I can receive any possible type and should
be able to make a look up of the form:
   and_possible_return_type operator->

Any help is highly appreciated, since my head already smokes of enumerating possible solutions...

With Kind Regards,

Ovanes Markarian


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