Code:
template
<
int TValue1
, int TValue2
, typename TWrappedFunction
>
struct Invoker
{
inline static bool Go
(
int fValue1
, int fValue2
)
{
if((TValue1 == fValue1) && (TValue2 == fValue2))
{
TWrappedFunction::template Apply<TValue1, TValue2>::Go();
return(true);
}
else
{
return(false);
}
}
};
template
<
int TValue1
, int TValue2
, typename TWrappedFunction
, int TOriginalValue1 = TValue1
, int TOriginalValue2 = TValue2
>
struct InterfaceBuilder // General Condition
{
inline static void Go
(
int fValue1
, int fValue2
)
{
if(!Invoker<TValue1, TValue2, TWrappedFunction>::Go(fValue1, fValue2))
{
InterfaceBuilder<TValue1, TValue2 - 1, TWrappedFunction, TOriginalValue1, TOriginalValue2>::Go(fValue1, fValue2);
}
}
};
template
<
int TValue1
, typename TWrappedFunction
, int TOriginalValue1
, int TOriginalValue2
>
struct InterfaceBuilder<TValue1, 0, TWrappedFunction, TOriginalValue1, TOriginalValue2> // Cyclical Condition
{
inline static void Go
(
int fValue1
, int fValue2
)
{
if(!Invoker<TValue1, 0, TWrappedFunction>::Go(fValue1, fValue2))
{
InterfaceBuilder<TValue1 - 1, TOriginalValue2, TWrappedFunction, TOriginalValue1, TOriginalValue2>::Go(fValue1, fValue2);
}
}
};
template
<
typename TWrappedFunction
, int TOriginalValue1
, int TOriginalValue2
>
struct InterfaceBuilder<0, 0, TWrappedFunction, TOriginalValue1, TOriginalValue2> // Terminating Condition
{
inline static void Go
(
int fValue1
, int fValue2
)
{
Invoker<0, 0, TWrappedFunction>::Go(fValue1, fValue2);
}
};
#include <iostream>
template
<
int TValue1
, int TValue2
>
void TergetFunction()
{
std::cout << "a general function: " << TValue1 << ':' << TValue2 << '\n';
}
template <> void TergetFunction<2, 3>()
{
std::cout << "a special function: " << 2 << ':' << 3 << '\n';
}
template <> void TergetFunction<7, 4>()
{
std::cout << "a different special function: " << 7 << ':' << 4 << '\n';
}
struct TergetFunctionWrapper
{
template
<
int TValue1
, int TValue2
>
struct Apply
{
inline static void Go()
{
TergetFunction<TValue1, TValue2>();
}
};
};
void TergetFunctionInterface
(
int fValue1
, int fValue2
)
{
InterfaceBuilder<8, 8, TergetFunctionWrapper>::Go(fValue1, fValue2);
}
int main()
{
int lValue1(0);
int lValue2(0);
std::cout << "enter two target values: _\b";
std::cin >> lValue1 >> lValue2;
TergetFunctionInterface(lValue1, lValue2);
return(0);
}