C++ range-v3庫的安裝與測試[Utunbu 18.04]


range-v3是C++14/17/20的一個Range庫。range-v3是C++標准庫(std庫)的基礎,其目標也是為了添加到C++標准庫之中。

range-v3通過技術規范的演變,最終形成了P0896R4 (https://wg21.link/p0896r4) 范圍提案文檔,並且在2018年11月合並到

C++20的工作草案(https://ericniebler.github.io/std/wg21/D4128.html)之中。

range庫是標准模板庫(std庫)的擴展,其目的是使標准模板庫的迭代器和算法成為可組合的(composable),使得其功能更強

大。

range-v3有三大支柱(pillar):Views(視圖), Actions(動作), and Algorithms(算法)。

視圖和動作通過管道(|)(range庫重載了|操作符)連接起來,使得代碼簡潔且從左到有很強的可讀性!

下載:

https://github.com/ericniebler/range-v3/tree/0.11.0
mkdir build
cd build
cmake ..
make
make install

測試:

#include <range/v3/all.hpp>
#include <iostream>
#include <string>

using std::cout;

int main(){
    std::string s{"hello"};
    ranges::for_each(s, [](char c) { cout << c << ' '; });
    cout << '\n';
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM