I know how to write a if else by meta-programming like this:
template<bool con, typename Then, typename Else>
struct IF;
template<typename Then, typename Else>
struct IF<true, Then, Else> {
typedef Then result;
};
template<typename Then, typename Else>
struct IF<false, Then, Else> {
typedef Else result;
};
template<int num1, int num2>
struct Add {
static const int value = num1 + num2;
};
template<int num1, int num2>
struct Sub {
static const int value = num1 - num2;
};
template<bool con, int num1, int num2>
struct addSub {
static const auto RES = IF<con, Add<num1, num2>, Sub<num1, num2>>::result::value;
};
cout << addSub<1==1, 10, 2>::RES << endl;
But I still have no idea how to write While loop like this, could someone give me a simple example?