Commit 9b7d7536 authored by BRAMAS Berenger's avatar BRAMAS Berenger

add a template runif for object

parent b0b9a030
......@@ -131,6 +131,43 @@ void Run(IterType value, Args... args){
}
///////////////////////////////////////////////////////////////////////////////////////
/// FRunIf : Compile all and exec only one (if the template variable is equal to
/// the first variable)
///////////////////////////////////////////////////////////////////////////////////////
namespace FRunIfThis{
template <class IterType, const IterType CurrentIter, const IterType iterTo, const IterType IterStep,
class Func, bool IsNotOver, typename... Args>
struct Evaluator{
static void Run(Func* object, IterType value, Args... args){
if(CurrentIter == value){
object->Func::template Run<CurrentIter>(args...);
}
else{
Evaluator<IterType, CurrentIter+IterStep, iterTo, IterStep, Func, (CurrentIter+IterStep < iterTo), Args...>::Run(object, value, args...);
}
}
};
template <class IterType, const IterType CurrentIter, const IterType iterTo, const IterType IterStep,
class Func, typename... Args>
struct Evaluator< IterType, CurrentIter, iterTo, IterStep, Func, false, Args...>{
static void Run(Func* object, IterType value, Args... args){
std::cout << __FUNCTION__ << " no matching value found\n";
}
};
template <class IterType, const IterType IterFrom, const IterType iterTo, const IterType IterStep,
class Func, typename... Args>
void Run(Func* object, IterType value, Args... args){
Evaluator<IterType, IterFrom, iterTo, IterStep, Func, (IterFrom<iterTo), Args...>::Run(object, value, args...);
}
}
///////////////////////////////////////////////////////////////////////////////////////
/// FRunIfFunctional : Compile all and exec only those whose respect a condition
///////////////////////////////////////////////////////////////////////////////////////
......
......@@ -47,6 +47,11 @@ struct RunClass {
void For(double mydouble, int myint){
std::cout << "RunClass::For >> P = " << P << " mydouble " << mydouble << " myint " << myint << "\n";
}
template <const int P>
void Run(double mydouble, int myint){
std::cout << "RunClass::Run >> P = " << P << " mydouble " << mydouble << " myint " << myint << "\n";
}
};
......@@ -65,6 +70,9 @@ int main(int argc, char** argv){
// This will call the Run method
FRunIf::Run<int, 0, 20, 1, RunContainer>(3, 45.4, 55);
// This will call the Run method
FRunIfThis::Run<int, 0, 20, 1, RunClass>(&runner, 3, 45.4, 55);
// Should not run, because 21 is out of the compiled interval
FRunIf::Run<int, 0, 20, 1, RunContainer>(21, 45.4, 55);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment