digitalmars.D.learn - about const ref
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (12/12) Feb 10 2020 I need to be sure about "const ref". Based on the following
- Mathias Lang (10/22) Feb 11 2020 You're correct for 'a' and 'b'. However `in` only entails
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (2/12) Feb 11 2020 Thank you for clarification.
I need to be sure about "const ref". Based on the following function, does it mean: Type can be string or an integral type. (a) k1 is not copied on function calls (b) k1 cannot be modified inside function Please correct me if I am wrong. Can storage class "in" be used to satisfy (a) and (b)? void doIt(const ref Type k1){ .... } Type k = ...; doit(k);
Feb 10 2020
On Tuesday, 11 February 2020 at 07:51:04 UTC, Ferhat Kurtulmuş wrote:I need to be sure about "const ref". Based on the following function, does it mean: Type can be string or an integral type. (a) k1 is not copied on function calls (b) k1 cannot be modified inside function Please correct me if I am wrong. Can storage class "in" be used to satisfy (a) and (b)? void doIt(const ref Type k1){ .... } Type k = ...; doit(k);You're correct for 'a' and 'b'. However `in` only entails `const`, so it is not an exact replacement. Additionally, you might want to add `scope` to show that the parameter does not escape. Note that a big limitation on `const ref` parameters at the moment is that it does not accept literals, which is something Andrei talked about a few years ago at DConf (or was it last year?).
Feb 11 2020
On Tuesday, 11 February 2020 at 09:20:11 UTC, Mathias Lang wrote:On Tuesday, 11 February 2020 at 07:51:04 UTC, Ferhat Kurtulmuş wrote:You're correct for 'a' and 'b'. However `in` only entails `const`, so it is not an exact replacement. Additionally, you might want to add `scope` to show that the parameter does not escape. Note that a big limitation on `const ref` parameters at the moment is that it does not accept literals, which is something Andrei talked about a few years ago at DConf (or was it last year?).Thank you for clarification.
Feb 11 2020