Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-06-22 14:54:34


Gottlob Frege wrote:
>> From: "Peter Dimov" <pdimov_at_[hidden]>
>> intrusive_ptr_add_ref is passed a pointer to a class with an
>> embedded reference count. It doesn't matter how many typedefs
>> resolve to X*, X still
>> has its reference count that needs to be incremented.
>>
>> You only run into the problem when "assign" is underspecified and
>> overloaded
>> to mean different things in different contexts.
>
>
>
> I understand your point, and maybe it is not a problem for
> intrusive_ptr in all pratical cases, but intrusive_ptr_add_ref is
> passed a T *. T may or may NOT be a class. ie T could be an int
> or an HWND (which is often just void *, depending on #define STRICT)
> or some other handle, or whatever.

It doesn't matter.

The point is that the type of an entity (by definition) determines the legal
operations on the entity, and the effects of these operations. (To be
precise, it's actually the reverse.)

In other words, if you have an operation F, and two type aliases X and Y
that both resolve to 'int' and you want F to have different semantics when
applied to X and Y, you are effectively not using the C++ type system. You
have imposed your own "logical type system" that is based on names (X and Y)
and not types.

If you need different (logical) types, you have to use different (physical)
types. typedef does not introduce a type. Similarly, if you want to not be
able to add meters and kilograms, you have to make meters and kilograms
distinct types. You can't solve this fundamental problem by making operator+
policy-based, because in 5 + 6, you have no way to know whether the 5 is 5m
or 5kg.


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