
Gottlob Frege wrote:
From: "Peter Dimov"
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.