#include<iostream>
#include"CtrlTmpl.h"

class TestIf
{
	template<typename Env>
	struct Tautology
	{
		static const bool cond = true;
	};
	
	template<typename Env>
	struct AntiTautology
	{
		static const bool cond = false;
	};
	
	template<typename Env>
	struct Success
	{
		typedef typename Env::SuccessValType Result;
		static const Result result = Env::SuccessVal;
	};
	
	template<typename Env>
	struct Failure
	{
		typedef typename Env::FailureValType Result;
		static const Result result = Env::FailureVal;
	};
	
	struct BoolConsts
	{
		typedef bool SuccessValType;
		static const SuccessValType SuccessVal = true;
		typedef bool FailureValType;
		static const FailureValType FailureVal = false;
	};

	public:
	
	static const bool success
		= If<BoolConsts, Tautology, Success, Failure>::Result::result
		&& If<BoolConsts, AntiTautology, Failure, Success>::Result::result;
};

class TestFor
{
	struct Init
	{
		typedef int AccType;
		static const AccType adder = 1;
		static const AccType sum = 0;
	};
	
	template<typename Enviroment>
	struct LoopCond
	{
		static const bool cond = (Enviroment::adder < 10);
	};
	
	template<typename Enviroment>
	struct LoopBody
	{
		struct Env
		{
			typedef typename Enviroment::AccType AccType;
			static const AccType adder = Enviroment::adder + 2;
			static const AccType sum = Enviroment::sum + Enviroment::adder;
		};
	};
	
	public:
	
	static const int total = For<Init, LoopCond, LoopBody>::Result::sum;
	static const bool success
		= (1+3+5+7+9 == total);
};

bool testCtrlTmpl(void)
{
	//std::cerr << "\n\t[Total: " << TestFor::total << "]\n";
	return (TestIf::success && TestFor::success);
}
