Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/stdcpp/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pure nothrow @nogc:
///
inout(T)* data() inout @safe { static if (N > 0) { return &_M_elems[0]; } else { return null; } }
///
ref inout(T[N]) as_array() inout @trusted { return data()[0 .. N]; }
ref inout(T)[N] as_array() inout @trusted { return cast(inout(T)[N])data()[0 .. N]; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like that cast should never be necessary. Could you explain why it is ?

Copy link
Contributor Author

@RazvanN7 RazvanN7 Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inout(T[N]) cannot be converted to inout(T)[]. Note that the function was @trusted because the compiler inserted a cast implicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you access _M_elems directly, which already has the correct type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted the change to be minimally invasive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better for it to be correct and avoiding casts.

///
ref inout(T) at(size_type i) inout @trusted { return data()[0 .. N][i]; }

Expand All @@ -117,7 +117,7 @@ pure nothrow @nogc:
///
inout(T)* data() inout @trusted { static if (N > 0) { return &__elems_[0]; } else { return cast(inout(T)*)__elems_.ptr; } }
///
ref inout(T)[N] as_array() inout @trusted { return data()[0 .. N]; }
ref inout(T)[N] as_array() inout @trusted { return cast(inout(T)[N])data()[0 .. N]; }
///
ref inout(T) at(size_type i) inout @trusted { return data()[0 .. N][i]; }

Expand Down