Dry Run Testing
Dry Run Testing
September 27, 2022
C++11's shared_from_this
C++11’s shared_from_this
October 11, 2022

October 4, 2022

The Ranges Library in C++20

The algorithms library of C++ can sometimes be a little inconvenient since most of them requires a begin and an end iterator to operate (1). Utilizing C++ 20's ranges library, container operations are much more readable and convenient (2).

#include <algorithm> 
#include <iostream> 
#include <vector>

int main() {
   std::vector<int> algVec{-3, 5, 0, 7, -4}; 
   std::sort(algVec.begin(), algVec.end()); // (1)
   std::vector<int> ranVec{8, 6, -2, 1, 0}; 
   std::ranges::sort(ranVec);              //(2)
}
The Ranges Library in C++20
This website uses cookies to improve your experience. By using this website you agree to our Data Privacy Statement
Read more