new explicit template argument specification workaround for FnDispatcher::Add
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@126 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
3419c5b069
commit
31b1b37ee9
1 changed files with 60 additions and 12 deletions
|
@ -13,23 +13,24 @@
|
||||||
// without express or implied warranty.
|
// without express or implied warranty.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Last update: Mar 20, 2003
|
// Last update: Mar 21, 2003
|
||||||
// Interface change for FnDispatcher::Add:
|
// Added a new explicit template argument specification workaround for
|
||||||
// The trampoline-Version of FnDispatcher::Add needs explicit template
|
// FnDispatcher::Add which is more compliant with other
|
||||||
// argument specification for type and non-type parameters. Unfortunately
|
// explicit template argument specification workarounds used in this port.
|
||||||
// all workarounds used so far failed for this member-function.
|
//
|
||||||
// Therefore I need to use a new one which leads to another interface change:
|
// Example usage:
|
||||||
// Example (see "Modern C++ Design" Section 11.6)
|
// --------------
|
||||||
// ----------------------------------------------
|
// Using the original library one writes:
|
||||||
// Using the original one writes:
|
|
||||||
// typedef FnDispatcher<Shape> Dispatcher;
|
// typedef FnDispatcher<Shape> Dispatcher;
|
||||||
// void Hatch(Rectangle& lhs, Poly& rhs) {...}
|
// void Hatch(Rectangle& lhs, Poly& rhs) {...}
|
||||||
//
|
//
|
||||||
// Dispatcher dis;
|
// Dispatcher dis;
|
||||||
// disp.Add<Rectangle, Poly, &Hatch>();
|
// disp.Add<Rectangle, Poly, &Hatch>();
|
||||||
//
|
//
|
||||||
// Using this port the example becomes:
|
// Using this port the example either becomes:
|
||||||
// Dispatcher::AddI<Rectangle, Poly, &Hatch>()(dis);
|
// dis.Add(Dispatcher::Add<Rectangle, Poly, &Hatch>());
|
||||||
|
// or alternatively
|
||||||
|
// Dispatcher::AddI<Rectangle, Poly, &Hatch>()(dis);
|
||||||
//
|
//
|
||||||
// All dispatchers now have void as default value for return types.
|
// All dispatchers now have void as default value for return types.
|
||||||
// All dispatchers now support void as return type.
|
// All dispatchers now support void as return type.
|
||||||
|
@ -553,7 +554,52 @@ namespace Private
|
||||||
::Loki::Type2Type<SomeRhs>());
|
::Loki::Type2Type<SomeRhs>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// two different workarounds for FnDispatcher::Add
|
||||||
|
// Using the first one writes:
|
||||||
|
// DisType dispatcher;
|
||||||
|
// dispatcher.Add(DisType::Etas<SomeLhs, SomeRhs, &AFunc>());
|
||||||
|
// using the second workaround the call becomes:
|
||||||
|
// DisType dispatcher;
|
||||||
|
// DisTyp::AddI<SomeLhs, SomeRhs, &AFunc>()(dispatcher);
|
||||||
|
|
||||||
|
// Helper-class for the first workaround.
|
||||||
|
// When calling FnDispatcher::Add provide an object of this type
|
||||||
|
// as argument.
|
||||||
|
template <class SomeLhs, class SomeRhs,
|
||||||
|
ResultType (*callback)(SomeLhs&, SomeRhs&), bool symmetric = false>
|
||||||
|
struct Etas
|
||||||
|
{
|
||||||
|
typedef Private::FnDispatcherHelper<
|
||||||
|
BaseLhs, BaseRhs, SomeLhs, SomeRhs, ResultType,
|
||||||
|
ApplyInnerType2<CastingPolicy, SomeLhs,BaseLhs>::type,
|
||||||
|
ApplyInnerType2<CastingPolicy,SomeRhs,BaseRhs>::type,
|
||||||
|
callback> Local;
|
||||||
|
enum {sym = symmetric};
|
||||||
|
typedef SomeLhs Lhs;
|
||||||
|
typedef SomeRhs Rhs;
|
||||||
|
};
|
||||||
|
|
||||||
|
// EtasType has to be a template parameter. If one tries to use
|
||||||
|
// a parameter of type Etas the MSVC 6.0 won't generate correct
|
||||||
|
// code.
|
||||||
|
template <class EtasType>
|
||||||
|
void Add(EtasType EtasObj)
|
||||||
|
{
|
||||||
|
typedef typename EtasType::Local Local;
|
||||||
|
typedef typename EtasType::Lhs SomeLhs;
|
||||||
|
typedef typename EtasType::Rhs SomeRhs;
|
||||||
|
|
||||||
|
Add(&Local::Trampoline, ::Loki::Type2Type<SomeLhs>(),
|
||||||
|
::Loki::Type2Type<SomeRhs>());
|
||||||
|
if (EtasType::sym)
|
||||||
|
{
|
||||||
|
Add(&Local::TrampolineR, ::Loki::Type2Type<SomeRhs>(),
|
||||||
|
::Loki::Type2Type<SomeLhs>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// alternative workaround for FnDispatcher::Add
|
||||||
template <class SomeLhs, class SomeRhs,
|
template <class SomeLhs, class SomeRhs,
|
||||||
ResultType (*callback)(SomeLhs&, SomeRhs&), bool symmetric = false>
|
ResultType (*callback)(SomeLhs&, SomeRhs&), bool symmetric = false>
|
||||||
struct AddI
|
struct AddI
|
||||||
|
@ -795,6 +841,8 @@ namespace Private
|
||||||
// Mar 20. 2003: Fixed Bugs in FnDispatcherHelperBase, FnDispatcher::Add and
|
// Mar 20. 2003: Fixed Bugs in FnDispatcherHelperBase, FnDispatcher::Add and
|
||||||
// FunctorDispatcher::Add.
|
// FunctorDispatcher::Add.
|
||||||
// New Interface for FnDispatcher::Add.B.K.
|
// New Interface for FnDispatcher::Add.B.K.
|
||||||
|
// Mar 21, 2003: Added new explicit template argument specification workaround
|
||||||
|
// for FnDispatcher::Add B.K.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue