Torque 3D 3.7

FastDelegate.h Efficient delegates in C++ that generate only two lines of asm code! Documentation is found at 

  • Don Clugston, Mar 2004.
Major contributions were made by Jody Hagins. 

24-Apr-04 1.0 * Submitted to CodeProject. 28-Apr-04 1.1 * Prevent most unsafe uses of evil static function hack.

  • Improved syntax for horrible_cast (thanks Paul Bludov).
  • Tested on Metrowerks MWCC and Intel ICL (IA32)
  • Compiled, but not run, on Comeau C++ and Intel Itanium ICL.
27-Jun-04 1.2 * Now works on Borland C++ Builder 5.5
  • Now works on /clr "managed C++" code on VC7, VC7.1
  • Comeau C++ now compiles without warnings.
  • Prevent the virtual inheritance case from being used on VC6 and earlier, which generate incorrect code.
  • Improved warning and error messages. Non-standard hacks now have compile-time checks to make them safer.
  • implicit_cast used instead of static_cast in many cases.
  • If calling a const member function, a const class pointer can be used.
  • MakeDelegate() global helper function added to simplify pass-by-value.
  • Added fastdelegate.clear()
16-Jul-04 1.2.1* Workaround for gcc bug (const member function pointers in templates) 30-Oct-04 1.3 * Support for (non-void) return values.
  • No more workarounds in client code! MSVC and Intel now use a clever hack invented by John Dlugosz:
    • The FASTDELEGATEDECLARE workaround is no longer necessary.
    • No more warning messages for VC6
  • Less use of macros. Error messages should be more comprehensible.
  • Added include guards
  • Added FastDelegate::empty() to test if invocation is safe (Thanks Neville Franks).
  • Now tested on VS 2005 Express Beta, PGI C++
24-Dec-04 1.4 * Added DelegateMemento, to allow collections of disparate delegates.
  • <,>,<=,>= comparison operators to allow storage in ordered containers.
    • Substantial reduction of code size, especially the 'Closure' class.
    • Standardised all the compiler-specific workarounds.
  • MFP conversion now works for CodePlay (but not yet supported in the full code).
  • Now compiles without warnings on _any_ supported compiler, including BCC 5.5.1
    • New syntax: FastDelegate< int (char *, double) >.
14-Feb-05 1.4.1* Now treats =0 as equivalent to .clear(), ==0 as equivalent to .empty(). (Thanks elfric).
  • Now tested on Intel ICL for AMD64, VS2005 Beta for AMD64 and Itanium.
30-Mar-05 1.5 * Safebool idiom: "if (dg)" is now equivalent to "if (!dg.empty())"
  • Fully supported by CodePlay VectorC
  • Bugfix for Metrowerks: empty() was buggy because a valid MFP can be 0 on MWCC!
  • More optimal assignment,== and != operators for static function pointers.

It works on Metrowerks MWCC 3.2.2. From boost.Config it should work on earlier ones too. 
Workaround GCC bug #8271 At present, GCC doesn't recognize constness of MFPs in templates 
This is macro FASTDELEGATE_H. 
Uncomment the following #define for optimally-sized delegates. In this case, the generated asm code is almost identical to the code you'd get if the compiler had native support for delegates. It will not work on systems where sizeof(dataptr) < sizeof(codeptr). Thus, it will not work for DOS compilers using the medium model. It will also probably fail on some DSP systems. 
CodePlay doesn't have the __single/multi/virtual_inheritance keywords 
Compiler identification. It's not easy to identify Visual C++ because many vendors fraudulently define Microsoft's identifiers. 
Does the compiler uses Microsoft's member function pointer structure? If so, it needs special treatment. Metrowerks CodeWarrior, Intel, and CodePlay fraudulently define Microsoft's identifier, _MSC_VER. We need to filter Metrowerks out. 
disable this ridiculous warning 
General tricks used in this code
(a) Error messages are generated by typdefing an array of negative size to generate compile-time errors. (b) Warning messages on MSVC are generated by declaring unused variables, and enabling the "variable XXX is never used" warning. (c) Unions are used in a few compiler-specific cases to perform illegal casts. (d) For Microsoft and Intel, when adjusting the 'this' pointer, it's cast to (char *) first to ensure that the correct number of *bytes* are added.
///////////////////////////////////////////////////////////////////////////// Helper templates 
Copyright (c) 2015. All rights reserved.
What do you think about this topic? Send feedback!