码迷,mamicode.com
首页 > 编程语言 > 详细

c++11之函数式编程实例

时间:2017-08-22 23:20:46      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:c++   isl   iso   int   end   ota   auto   clu   函数   

#ifndef LEAPYEAR_INCLUDED
#define LEAPYEAR_INCLUDED

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


#include "leapyear.hpp"

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

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

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;
}

c++11之函数式编程实例

标签:c++   isl   iso   int   end   ota   auto   clu   函数   

原文地址:http://www.cnblogs.com/atoman/p/7413743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!