Add const_pointer_cast(global_ptr<U>)

Issue #56 resolved
Amir Kamil created an issue

We currently allow explicit conversions between global_ptr<T> and global_ptr<char>. I propose we remove this and instead follow the pattern of std::shared_ptr to introduce a full set of pointer casts (http://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast). This would also enable polymorphic casts.

Proposed API:

namespace upcxx {

  template<typename T, typename U>
  global_ptr<T> static_pointer_cast(global_ptr<U> ptr);

  template<typename T, typename U>
  global_ptr<T> dynamic_pointer_cast(global_ptr<U> ptr);

  template<typename T, typename U>
  global_ptr<T> const_pointer_cast(global_ptr<U> ptr);

  template<typename T, typename U>
  global_ptr<T> reinterpret_pointer_cast(global_ptr<U> ptr);

} // namespace upcxx

We would specify similar semantics and constraints as in http://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast. For dynamic_pointer_cast, we would additionally require ptr.is_local().

On a tangential note, we should also add a type member global_ptr<T>::element_type that aliases T.

Comments (12)

  1. Amir Kamil reporter

    I'm not in favor of providing dynamic_pointer_cast, as it cannot be done locally. The others are doable without any communication.

  2. Dan Bonachea

    const_pointer_cast doesn't seem terribly useful until we resolve issue #51, as users would be wise to avoid global_ptr<const T> entirely until then

  3. Log in to comment