-
Notifications
You must be signed in to change notification settings - Fork 85
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
non-const reference to underlying type #11
Comments
Hi Arvid, |
I take you specifically refer to the case of traditional code taking a parameter by non-const reference, as an out-parameter. If it's just a matter of casting the result of non-typesafe function into the correct type, one can just use the constructor. Since out-parameters are being phased out (and generally recommended against) in favor of multiple return values. In my mind, the cost of introducing this loophole in the type-safety is not worth the case of supporting out-parameters. Requiring a copy for out-parameters seem like a reasonable disincentive to use them. I suppose the other use case would be supporting |
Yep, totally in line with you on discouraging out-parameters. The case I was thinking about was like int f(); Does this look like a valid use case to you? |
I see. In my mind, that should be typed as:
But you won't really get all the type-safety benefits until |
I agree with @arvidn, getting rid of the non-const
|
Hello Florian, I get your point. Would it be good to have it as an opt-in skill then? Because having this setter can be handy in some cases, like for introducing strong types in an existing piece of code that performs sets. Jonathan |
my opinion is that along the edges of introducing strong types, it's a feature for the conversions to be verbose and explicit. The two cases I can think of is where a weak type is returned normally and where it's returned as an out-parameter. I think the normal way to deal with that should be:
Partly because the out-param case should be a bit extra penalised (because it represents two separate fixes that need to be made). |
If the user want to add the I believe that the access to the underlying type should return a reference/const reference, but the name shouldn't be something friendly. I have used a backdoor idiom to state clearly that the mixin are using something that in principle can be used only by the mixins. I access it as If the user wants to declare a |
It seems like having a
get()
overload return a non-const reference to the underlying type is a pretty big safety risk, essentially circumventing all the type restrictions put in place withNamedType
.My understanding is that this function is quite widely used by the Skills, which makes sense that they would have access to a non-const reference to the underlying object. But perhaps it would make sense to make the non-const
get()
overload be protected, so it's only available to the skills, and not part of the public API.The text was updated successfully, but these errors were encountered: