Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added []= value assignment for smart pointers #52

Merged
merged 1 commit into from
Nov 10, 2022
Merged

added []= value assignment for smart pointers #52

merged 1 commit into from
Nov 10, 2022

Conversation

JorySchossau
Copy link
Contributor

pass-by-reference (var) was not used here because these additions are about changing the values pointed to by the pointers, regardless if the pointer itself is mutable. ConstPtr correctly yields an informative error on attempted value assignment.

@@ -51,6 +51,8 @@ proc `[]`*[T](p: UniquePtr[T]): var T {.inline.} =
assert(p.val != nil, "deferencing nil unique pointer")
p.val[]

proc `[]=`*[T](p:UniquePtr[T], v:T) {.inline.} = (p[]) = v
Copy link
Contributor

@planetis-m planetis-m Dec 12, 2020

Choose a reason for hiding this comment

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

can you please assign to p.val directly, seems wasteful to go through a function call

Copy link
Contributor

Choose a reason for hiding this comment

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

oh its inline, so maybe no need to.

Copy link
Contributor Author

@JorySchossau JorySchossau Dec 14, 2020

Choose a reason for hiding this comment

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

Thanks for reviewing! Yeah, I made it inline in lieu of p.val since that was the existing design for the other procs. I just followed suit.

@Araq Araq merged commit 39a9fcc into nim-lang:master Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants