Re: Get calling this, if exists

2016-06-24 Thread Ali Çehreli via Digitalmars-d-learn
On 06/24/2016 10:19 AM, Smoke Adams wrote: > We have __FUNCTION__ so, __THIS__ seems somewhat natural. Null for > outside of objects is fine. Would the following work, where you check the first argument? import std.stdio; void Log(string filename = __FILE__, T...)(T args) { static if (is

Re: Get calling this, if exists

2016-06-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/24/16 1:19 PM, Smoke Adams wrote: The problem with UFCS is that I am using variadic parameters. The logging function isn't designed to accept the first parameter as this. Then you would need to change it? It would be much easier to simply have the compiler "insert" it using __THIS__.

Re: Get calling this, if exists

2016-06-24 Thread Smoke Adams via Digitalmars-d-learn
On Friday, 24 June 2016 at 15:35:57 UTC, Steven Schveighoffer wrote: On 6/24/16 11:15 AM, Smoke Adams wrote: On Friday, 24 June 2016 at 03:16:58 UTC, Meta wrote: On Friday, 24 June 2016 at 03:10:51 UTC, Mike Parker wrote: Oh, perhaps I misunderstood your question. Do you meant this: class

Re: Get calling this, if exists

2016-06-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/24/16 11:15 AM, Smoke Adams wrote: On Friday, 24 June 2016 at 03:16:58 UTC, Meta wrote: On Friday, 24 June 2016 at 03:10:51 UTC, Mike Parker wrote: Oh, perhaps I misunderstood your question. Do you meant this: class Foo() { void bar() { Log(); } // Pass reference to Foo instance }

Re: Get calling this, if exists

2016-06-24 Thread Smoke Adams via Digitalmars-d-learn
On Friday, 24 June 2016 at 03:16:58 UTC, Meta wrote: On Friday, 24 June 2016 at 03:10:51 UTC, Mike Parker wrote: Oh, perhaps I misunderstood your question. Do you meant this: class Foo() { void bar() { Log(); } // Pass reference to Foo instance } void doSomething() { Log(); } // Null

Re: Get calling this, if exists

2016-06-23 Thread Meta via Digitalmars-d-learn
On Friday, 24 June 2016 at 03:10:51 UTC, Mike Parker wrote: Oh, perhaps I misunderstood your question. Do you meant this: class Foo() { void bar() { Log(); } // Pass reference to Foo instance } void doSomething() { Log(); } // Null reference If so, the answer is no. And I don't see how

Re: Get calling this, if exists

2016-06-23 Thread Mike Parker via Digitalmars-d-learn
On Friday, 24 June 2016 at 03:04:25 UTC, Mike Parker wrote: On Friday, 24 June 2016 at 02:57:28 UTC, "Smoke" Adams wrote: Is there a type of __THIS__ construct similar to __FILE__ and __LINE__? Something that returns the current this ptr if it exists, null otherwise. Log(string filename =

Re: Get calling this, if exists

2016-06-23 Thread Mike Parker via Digitalmars-d-learn
On Friday, 24 June 2016 at 02:57:28 UTC, "Smoke" Adams wrote: Is there a type of __THIS__ construct similar to __FILE__ and __LINE__? Something that returns the current this ptr if it exists, null otherwise. Log(string filename = __FILE__, Object obj = __THIS__)() { // inspect obj and do

Get calling this, if exists

2016-06-23 Thread Smoke Adams via Digitalmars-d-learn
Is there a type of __THIS__ construct similar to __FILE__ and __LINE__? Something that returns the current this ptr if it exists, null otherwise. Log(string filename = __FILE__, Object obj = __THIS__)() { // inspect obj and do stuff }