Is it possible to use opDispatch as generic getter and setter at the
same time? Something like __get() and __set() in PHP..
this is what I've tried: https://gist.github.com/895571
and I get Error: template instance opDispatch!("bar") matches more
than one template declaration, path\to\test.d(57):opDispatch(string
entryName) and path\to\test.d(66):opDispatch(string entryName)
Is mixing property with opDispatch supposed to work at all or is
opDispatch only ment for method calls?
Or maybe there is some other way to achive what I want and I'm not
aware of it? :-)

Is it possible to use opDispatch as generic getter and setter at the
same time? Something like __get() and __set() in PHP..
this is what I've tried: https://gist.github.com/895571
and I get Error: template instance opDispatch!("bar") matches more
than one template declaration, path\to\test.d(57):opDispatch(string
entryName) and path\to\test.d(66):opDispatch(string entryName)
Is mixing property with opDispatch supposed to work at all or is
opDispatch only ment for method calls?
Or maybe there is some other way to achive what I want and I'm not
aware of it? :-)

That's great! Thanks! If just the assignment worked thought, it would
be perfect..
Btw, do you know which issue # that is? I'd like to read more about
that bug but can't find it on bugzilla.
On Thu, Mar 31, 2011 at 3:50 AM, spir <denis.spir gmail.com> wrote:

Agreed. And I would really have an answer to your question, since I tried to
do the same thing. Don't understand why D does not have an 'opMember' or
'opDot'. Someone knows?
This would be one of the first metamethods I would introduce in a language
(definitely before operator overloading).

Yeah, opMember would be great, but it seems that we'll be able to use
opDispatch for that in a way Jacob described once the bugs are ironed
out..
But until then I'll have to live with "ugly" indexing sytnax...

Is it possible to use opDispatch as generic getter and setter at the
same time? Something like __get() and __set() in PHP..
this is what I've tried: https://gist.github.com/895571
and I get Error: template instance opDispatch!("bar") matches more
than one template declaration, path\to\test.d(57):opDispatch(string
entryName) and path\to\test.d(66):opDispatch(string entryName)
Is mixing property with opDispatch supposed to work at all or is
opDispatch only ment for method calls?
Or maybe there is some other way to achive what I want and I'm not
aware of it? :-)

The issue is that you can't have two templates with the same exact
template parameters, even if they have different function parameters.
This is because the compiler first instantiates the template, then calls
the function.
I hope this restriction can be lifted for the special case of template
functions. The ability to overload template functions is long overdue,
especially when you are overloading with normal functions.

The issue is that you can't have two templates with the same exact
template parameters, even if they have different function parameters.
This is because the compiler first instantiates the template, then calls
the function.

If two template instances have the same exact template parameters, it's one
instance, isn't it? There's no need to instantiate it twice.

The issue is that you can't have two templates with the same exact
template parameters, even if they have different function parameters.
This is because the compiler first instantiates the template, then calls
the function.

If two template instances have the same exact template parameters, it's
one instance, isn't it? There's no need to instantiate it twice.

Yes, but we allow function overloading. Problem is, you can't do
*template* function overloading unless you do it on the template
parameters.
For instance, these two cannot be instantiated:
void foo(string s)(int x) {writeln(x);}
void foo(string s)(string y) {writeln(y);}
because the compiler considers that you defined the same template twice
with different implementations.
However, if you do:
void foo(string s, T)(T x) if (is(T == int)) { writeln(x); }
void foo(string s, T)(T x) if (is(T == string)) { writeln(x); }
then you have two different templates, and the compiler has no issue.
This is a huge nuisance for operator overloading and opDispatch because
the only required template parameter is the string of the
operator/function name.
I suspect that fixing this will be a large change in the compiler.
-Steve

Is it possible to use opDispatch as generic getter and setter at the
same time? Something like __get() and __set() in PHP..
this is what I've tried: https://gist.github.com/895571
and I get Error: template instance opDispatch!("bar") matches more
than one template declaration, path\to\test.d(57):opDispatch(string
entryName) and path\to\test.d(66):opDispatch(string entryName)
Is mixing property with opDispatch supposed to work at all or is
opDispatch only ment for method calls?
Or maybe there is some other way to achive what I want and I'm not
aware of it? :-)

Bug 620[1] is related to what you ask. I have written a solution there,
but I do not remember how well it works, and have no way of testing it
currently:
template opDispatch( string name ) {
auto opDispatch( T... )( T args ) {
// Do something!
}
}
[1]: http://d.puremagic.com/issues/show_bug.cgi?id=3D620
-- =
Simen

Bug 620[1] is related to what you ask. I have written a solution there,
but I do not remember how well it works, and have no way of testing it
currently:
template opDispatch( string name ) {
=C2=A0 =C2=A0auto opDispatch( T... )( T args ) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0// Do something!
=C2=A0 =C2=A0}
}
[1]: http://d.puremagic.com/issues/show_bug.cgi?id=3D620
--
Simen