Skip to content

[SUGGESTION] unsafe_narrow is not a good name for forced upcasts. #510

Description

@MaxSagebaum

If you have e.g. expression templates, then the upcast to the implementing class needs to be done with unsafe_narrow.

Maybe an alias of unsafe_narrow like unsafe_cast, 'unsafe_pointer_cast` or something like that could be introduced.

Example: https://cpp2.godbolt.org/z/jb1MY3Mcq

Exp : <Impl> type = {  
  cast: (this) -> forward Impl = cpp2::unsafe_narrow<Impl>(this&)*; // unsafe_narrow does not really express what this cast is.
}

A : type = {
  this: Exp<A> = ();
  foo: (this) = std::cout << "foo" << std::endl;
}

main: () -> int = {
  a: A = ();
  e: *Exp<A> = a&;

  e*.cast().foo();

  return 0;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions