digitalmars.D.learn - overloading evaluation (treating objects as functions)
- dan (16/16) May 17 2015 Is it possible to define a class F so that
- Namespace (2/19) May 17 2015 http://dlang.org/operatoroverloading.html#function-call
- Gary Willoughby (16/17) May 17 2015 Like this:
- dan (5/22) May 17 2015 Awesome!!
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/6) May 17 2015 There is the following short section as well:
Is it possible to define a class F so that
auto f=new F();
writeln("The value of f at 7 is ",f(7));
compiles and works as expected?
So the idea would be to be able to use notation like
f(7)
instead of
f.eval(7)
or something along those lines.
My guess is no, it is impossible to do this, because i can't find
it on the internet or in Alexandrescu's book.
But it is also possible that everybody considers it so obvious
that they just don't elaborate on it. I'd be delighted if there
were the case, at least if somebody would elaborate on it if so.
TIA for any info!
dan
May 17 2015
On Sunday, 17 May 2015 at 18:49:40 UTC, dan wrote:
Is it possible to define a class F so that
auto f=new F();
writeln("The value of f at 7 is ",f(7));
compiles and works as expected?
So the idea would be to be able to use notation like
f(7)
instead of
f.eval(7)
or something along those lines.
My guess is no, it is impossible to do this, because i can't
find it on the internet or in Alexandrescu's book.
But it is also possible that everybody considers it so obvious
that they just don't elaborate on it. I'd be delighted if
there were the case, at least if somebody would elaborate on it
if so.
TIA for any info!
dan
http://dlang.org/operatoroverloading.html#function-call
May 17 2015
On Sunday, 17 May 2015 at 18:58:32 UTC, Namespace wrote:http://dlang.org/operatoroverloading.html#function-callLike this: module main; import std.stdio; class F { int opCall(int value) { return value * 2; } } void main(string[] args) { auto f = new F(); writeln("The value of f at 7 is ", f(7)); }
May 17 2015
Awesome!! Thanks Gary and namespace (and obviously i gotta improve my google-fu). dan On Sunday, 17 May 2015 at 19:40:10 UTC, Gary Willoughby wrote:On Sunday, 17 May 2015 at 18:58:32 UTC, Namespace wrote:http://dlang.org/operatoroverloading.html#function-callLike this: module main; import std.stdio; class F { int opCall(int value) { return value * 2; } } void main(string[] args) { auto f = new F(); writeln("The value of f at 7 is ", f(7)); }
May 17 2015
On 05/17/2015 11:49 AM, dan wrote:i can't find it on the internetThere is the following short section as well: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opCall Ali
May 17 2015









"dan" <dan.hitt gmail.com> 