[Issue 7802] UFCS functions get lost when type is transmitted to template
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Apr 5 01:01:10 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7802
--- Comment #8 from Kenji Hara <k.hara.pg at gmail.com> 2012-04-05 01:01:35 PDT ---
There is two different situations around template instantiations and UFCS.
See following example.
--- kernel.d ---
struct S { int val; }
@property int foo(ref S s) { return s.val; }
--- extra.d ---
import kernel;
@property int bar(ref S s) { return s.val * 2; }
--- util.d ---
auto testfoo(T)(T t) { return t.foo; }
auto testbar(T)(T t) { return t.bar; }
--- test.d ---
import kernel, extra, util;
void main()
{
auto s = S(1);
assert(s.foo == 1); // mod.foo(s), OK
assert(s.bar == 2); // extra.bar(s), OK
assert(testfoo(s) == 1); // cannot instantiate
assert(testbar(s) == 2); // cannot instantiate
}
Walter's suggestion supports both testfoo and testbar, but I'm afraid that it
causes code bloating.
Steven's suggestion supports testfoo, but cannot support testbar.
I think Steven's way and the case of testfoo is similar to C++ ADL. But in D, a
namespace associated with a module is not opened, so unintended name lookup
isn't in there.
But, the case of testbar requires making relations between kernel and extra
modules in test.d module. For now I have no idea about it.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list