Re: Retrieve the return type of the current function

2020-05-06 Thread learner via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 08:04:16 UTC, Jacob Carlborg wrote: On 2020-05-05 19:11, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: Yes,

Re: Retrieve the return type of the current function

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-05 19:11, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: Yes, kind of: void foo(string caller = __FUNCTION__)() { import

Re: Retrieve the return type of the current function

2020-05-05 Thread Meta via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 18:19:00 UTC, Meta wrote: mixin template magic() { alias CallerRet = typeof(return); CallerRet magic() { return CallerRet.init; } } Small edit: you can remove the "CallerRet" alias by doing the following: mixin template magic() {

Re: Retrieve the return type of the current function

2020-05-05 Thread Meta via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 17:11:53 UTC, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: ``` int foo() { return magic(); } auto

Re: Retrieve the return type of the current function

2020-05-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 5, 2020 11:11:53 AM MDT learner via Digitalmars-d-learn wrote: > On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: > > typeof(return) > > Thank you, that was indeed easy! > > Is it possible to retrieve also the caller return type? Something > like: > > ``` > int foo() {

Re: Retrieve the return type of the current function

2020-05-05 Thread learner via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: ``` int foo() { return magic(); } auto magic(maybesomedefaulttemplateargs = ??)() { alias R =

Re: Retrieve the return type of the current function

2020-05-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 16:36:48 UTC, learner wrote: I mean, without using the function name in the body, like ReturnType!foo ? even easier: typeof(return)

Retrieve the return type of the current function

2020-05-05 Thread learner via Digitalmars-d-learn
Good morning, Is it possible something like this? ``` int foo() { __traits(some_trait, some_generic_this) theInt = 0; ``` I mean, without using the function name in the body, like ReturnType!foo ?