|
|
RetroX
|
 |
Reply #17 Posted on: January 07, 2011, 08:55:20 pm |
|
|
Master of all things Linux
 Location: US Joined: Apr 2008
Posts: 1055
|
Suppose f1 and f2 return 0, and obj2.array[0,0] = 0.
The statement would be equivalent to the following: obj1.a = 0;
As you can see, I'm totally lost, which is why someone needs to explain this one to me.
f1() is performed for all objects, f2() is performed for objects, and set to a for all objects. It would be expansion hell, and really, in the end, the last one executed would actually be stored. That's why it's a bad idea to make one variable operate on multiple objects.
|
|
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars? 
|
|
|
polygone
|
 |
Reply #18 Posted on: January 08, 2011, 07:02:47 am |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
Suppose f1 and f2 return 0, and obj2.array[0,0] = 0.
The statement would be equivalent to the following: obj1.a = 0;
As you can see, I'm totally lost, which is why someone needs to explain this one to me.
As RetroX has just said, because what if there are multiple instances of obj1 and obj2? You can't run things so straight then. f1 and f2 might return different values depending on the instance it was executed with. RetroX has stated as a solution: in the end, the last one executed would actually be stored But to me this is really not nice and I don't think it is a viable solution. Which is why I mentioned previously: obj.a = obj.f1(); People would naturally expect this to work like: with (obj) { a = f1(); } But it would instead work like: global var ______ENIGMATEMP; with (obj) { ______ENIGMATEMP = f1(); } with (obj) { a = ______ENIGMATEMP; }
|
|
« Last Edit: January 08, 2011, 07:11:31 am by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
Josh @ Dreamland
|
 |
Reply #20 Posted on: January 08, 2011, 11:22:38 am |
|
|
Prince of all Goldfish
 Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Unfortunately, r9k, it's not that simple. It's not as simple as polygone's suggestion, either. The only way to implement this cleanly is too flawed to implement:
obj1.func()
becomes
(enigma::with_iter(obj1), func())
When the expression starts, it will be as though it was executed for obj1. When the expression ends, the with_iter will destruct, and the code will be back in its original scope. However, this will fail catastrophically:
obj1.func(obj2.func())
Both will be executed for obj2. This is because at the beginning of the expression, obj1 is pushed as the current instance, then obj2 is as well.
I haven't yet found a way around this.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
|
Josh @ Dreamland
|
 |
Reply #24 Posted on: January 09, 2011, 12:41:29 am |
|
|
Prince of all Goldfish
 Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
That's how with_iter works, luis. Issue is, you just passed func() the return value of enigma::pop_with().
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
luiscubal
|
 |
Reply #25 Posted on: January 09, 2011, 08:09:54 am |
|
|
 Joined: Jun 2009
Posts: 452
|
I see. What about:
(enigma::push_with(obj1), enigma::pop_with((enigma::push_with(obj2), enigma::pop_with(func())))) where pop_with(K) returns K.
If with_iter is already a stack, then I don't see how "obj1.func(obj2.func())" would fail. After all:
(enigma::with_iter(obj1), func((enigma::with_iter(obj2), func()))) The inner func is called after obj2 is pushed to the stack, and before it is poped, so it is applied to obj2 alone, the top() of the stack(assuming a STL stack) The outer func is called after obj1 and obj2 are pushed to the stack, but obj2 was already poped, so obj1 is the top() of the stack and therefore func() is applied to obj1 alone.
So I think it would work. That is, unless C++ sequence points are playing tricks on me.
|
|
|
Logged
|
|
|
|
Josh @ Dreamland
|
 |
Reply #26 Posted on: January 09, 2011, 01:12:24 pm |
|
|
Prince of all Goldfish
 Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
The stack is pushed twice at the beginning of the expression in my example, then popped twice right after.
pop_with(K) was what I was considering. But it wasn't until you posted it again that I realized I was thinking about it incorrectly. My first instinct was that there'd be no way to instantiate a template because the return type of func() can't be gathered from &func. But now I see that a simple template function would have done it.
inline template<typename any> any& pop_with(any &r) { return r; }
So thank you, Luis; the simplicity of the matter escaped me.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|