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;
} 本文由用戶 nbby 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!