"Alf P. Steinbach" <al***@start.no wrote in message
news:4s******** ****@mid.indivi dual.net...
>* Chris Thomasson:
>I am working on a high-speed futures implementation in C++,
[...]
>I was wondering if I was subjecting my first attempt at a function
pointer to any undefined behavior(s). Here is the code:
http://appcore.home.comcast.net/vzoo...cope-guard.cpp
I'm basically using Andrei and Petru scopeguard technique, with one small
tweak:
[...]
>So, I can call it virtually, or locally through the templated SafeWxecute
function... Does this sound Kosher to you C++ gurus'?
;^)
No. A scopeguard's job is to clean up.
Okay... I think the name I used for the object didn't safely match its
functionality. Therefore, I will rename the entire object to something like:
'funcall_base' which will not call anything in the destructor; it won't use
its scope in any aspect of its functionality.. .
Executing the clean-up action more than once is bound to lead to problems.
Then I can add a variant called 'funcall_scoped ' which will indeed invoke
the call in its destructor, only if it was not previously "Dismissed" . That
should define my indented usage a bit clearer than before...
If you want a "delegate", a callable entity that wraps an object pointer
plus member function pointer,
That's kind of what I am after, except I kind of want to stay away from
virtual destructors/functions in 'funcall_base' because it ultimately has to
be a POD that is compatible with my low-level C/Assembly library, which
contains the actual implementation details of my new futures algorithm. It
should have a single member which is a function pointer of a type that is
"standard" to my low-level library:
class funcall_base {
typedef void (*fpfuturesapi_ t) (void const*);
fpfuturesapi_t m_fpcall_virtua l;
};
So that the library can call it directly to get the actual templated
implementation details to invoke itself. Also, I think I can skip calls
into the function pointer contained in 'funcall_base':
class funcall_base {
public:
void execute_virtual () {
m_fpcall_virtua l(this);
}
};
when the type of its templated call details are known by the caller in
advance:
class funcall_base {
public:
template<typena me T_calldetail>
void execute_proxy() {
static_cast<T_c alldetail*>(thi s)->execute_direct ();
}
};
// assume mycall is base class of calldetails_t
funcall_base mycall;
// I think that this call:
mycall.execute_ virtual();
// should have more overhead than this call:
mycall.execute_ proxy<calldetai ls_t>();
// Am I way off base here?
:^)
I would appreciate it if you could clarify a bit...
consider the standard library and Boost/TR1 classes for that. The Boost
classes are superior because they build on the experience with the
standard library, plus additional techniques developed after 1998.
Unfortunately, I can't make use of any part of Boost, or any other
third-party library, in the implementation details of my C++ futures
library.
;^(...
Thanks for your patience!