微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

FunctionalPlus C++ 编码库

程序名称:FunctionalPlus

授权协议: BSL

操作系统: 跨平台

开发语言: C/C++

FunctionalPlus 介绍

FunctionalPlus
一个小的表头库,它可以降低代码噪声,一次只处理一个单一等级的的抽象对象。通过增加你的代码的简洁性和可维护性来提高生产效率和编码乐趣。从长远的角度来看,它可以通过提供易于使用的功能将你从实现控制的流中解放出来。

示例代码

#include "FunctionalPlus/FunctionalPlus.h"#include <iostream>
// std::list<std::uint64_t> collatzSeq(std::uint64_t x) { ... }int main()
{    using namespace FunctionalPlus;
    using namespace std;

    typedef list<uint64_t> Ints;    
    // [1, 2, 3 ... 29]
    auto numbers = GenerateIntegralRange<Ints>(1, 30);    
    // A function that does [1, 2, 3, 4, 5] -> "[1 => 2 => 3 => 4 => 5]"
    auto ShowInts = Bind1of2(ShowContWith<Ints>, " => ");    
    // A composed function that calculates a collatz sequence and shows it.
    auto ShowCollatsSeq = Compose(collatzSeq, ShowInts);    
    // Apply it to all our numbers.
    auto seqStrs = Transform(ShowCollatsSeq, numbers);    
    // Combine the numbers and their sequence representations into a map.
    auto collatzDict = CreateMap(numbers, seqStrs);    
    // Print some of the sequences.
    cout << collatzDict[13] << endl;
    cout << collatzDict[17] << endl;
}

FunctionalPlus 官网

https://github.com/Dobiasd/FunctionalPlus

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐