
I have a class that has the cool pubic member access without "()", like "left" and "right" for boost::bimap. In my case, it's meant to simulate a function object, so it can be passed to functions like std::for_each, and the return value from said functions (the updated function object) can be assigned back to the special member. This function object forwards to the actual computation object within my class object. I implemented this by making a special inner private class and have the auxiliary function object be a public data member of that private type. The actual computation object isn't directly in my class object, but within the public auxiliary member. So the auxiliary function object can be passed by copy or assignment and everything works. The problem is in a class derived from my first one. It also has a public auxiliary function object data member. However, it forwards to the SAME actual computation object as the base class's auxiliary member. I implemented this by the derived class's auxiliary keeping a pointer to the computation object within the base's auxiliary. The issue is when I create temporary derived-auxiliaries for use in std::for_each. I have to create a copy of the computation object with new and delete on destruction. The derived-auxiliary keeps a bool flag indicating whether the pointer points to a contained object or a heap one. I was thinking of making a boost::variant<CompObj, CompObj*> instead, but trades use of the heap for temporaries for making all derived-auxiliaries huge (if sizeof(CompObj) > sizeof (CompObj*)): Current: base's CompObj + derived's CompObj* and bool New: base's CompObj + derived's variant -> base's CompObj + derived's max(CompObj, CompObj*) -> 2 * CompObj (None of these include the various administrative padding or "otherwise empty" bytes.) I haven't changed it yet because I suspect this is a bad trade-off. But what happens on systems with low/no heaps? Should this be some sort of macro switch? -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
participants (1)
-
Daryle Walker