Created
August 23, 2015 19:57
-
-
Save martinmoene/ec85022ce720852125c4 to your computer and use it in GitHub Desktop.
C++ example of proposed clamp() used with range-v3 library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clamp-range-v3 | |
#include <iostream> | |
#include <clamp.hpp> | |
#include <range/v3/core.hpp> | |
#include <range/v3/view/iota.hpp> | |
#include <range/v3/view/remove_if.hpp> | |
#include <range/v3/view/transform.hpp> | |
struct is_odd | |
{ | |
bool operator()(int i) const | |
{ | |
return (i % 2) == 1; | |
} | |
}; | |
int main() | |
{ | |
using namespace ranges; | |
auto && rng = | |
view::iota(0, +20) | | |
view::remove_if( is_odd() ) | | |
view::transform( [](int x) { return clamp(x, 5, 15); } ); | |
std::cout << rng; | |
} | |
#if 0 | |
g++ -std=c++11 -I"../clamp (Dropbox)" -I../range-v3/include -I.. -o clamp-range-v3.exe clamp-range-v3.cpp && clamp-range-v3.exe | |
[5,5,5,6,8,10,12,14,15,15] | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment