c++11之函數式編程實例

#ifndef LEAPYEAR_INCLUDED
#define LEAPYEAR_INCLUDEDide

class LeapYear
{
public:
bool IsLeapYear(int year);
};
#endifclass


#include "leapyear.hpp"di

auto Or = [](bool a,bool b)->bool{ return a||b; };vi

auto And = [](bool a,bool b)->bool{ return a&&b; };return

auto Not = [](bool a)->bool{ return !a; };

auto Aliquot = [](int dividend,int divisor){return dividend%divisor == 0;};

bool LeapYear::IsLeapYear(int year){ auto aliquotby4 = Aliquot(year,4); auto notaliquotby100 = Not(Aliquot(year,100)); auto aliquotby400 = Aliquot(year,400); auto leapyear = Or(And(aliquotby4,notaliquotby100),aliquotby400); return leapyear;}

相關文章
相關標籤/搜索