http://d.puremagic.com/issues/show_bug.cgi?id=9238
--- Comment #8 from Kenji Hara <[email protected]> 2012-12-29 23:39:37 PST --- (In reply to comment #7) > And what's the problem with leaving auto ref as it is with templated functions In recent, I have used `auto ref` in std.algorithm.forward. Yes, ideally we can remove current 'templated auto ref'. There is an alternative solution (Make two overloaded functions - one receives rvalue, and the other receives lvalue -, and then @disable either one). But it is a breaking change, as you say "It subverts what in currently does". `in ref` is very recently allowed from 2.060. `auto ref` is from 2.038. Then, removing current `auto ref` is much impact than changing `in ref` meaning. > rvalues already work just fine with auto ref and templated functions. It's > just > non-templated functions which lack a solution. > Once scope has actually been fixed to actually check for escaping references, > you'll either end up with conflicting behavior with in depending on whether > it's ref or not, or you'll end up with scope's restrictions on it, which > would be horrendously over-restrictive. At least it is a necessary restriction for `in ref`. For example, we should not allow following code. ref T foo(in ref T t) { return t; } If foo _actually_ receives a lvalue, returning t by ref is valid. But, if foo receives an rvalue, foo accidentally returns a dangling reference, and it's completely unsafe. So, we must select a conservative way at the point. --- Here, I want to double-check the feature which is discussed. Current `auto ref` with template function makes one or more template instances based on the actual argument lvalue-ness. It might cause template bloating, and for big size rvalue, object bit-copy is inefficient. On the other hand, the discussed feature in the forum is as like "const T& in C++". It can bind both lvalue and rvalue, and it will be passed to function via "reference" (e.g. pointer). And, it works with non-template functions, and template instantiation is not related. Right? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
