Skip to content

Instantly share code, notes, and snippets.

@xfbs
Created January 29, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xfbs/37f71bf10494170bad1b6f37da332154 to your computer and use it in GitHub Desktop.
Save xfbs/37f71bf10494170bad1b6f37da332154 to your computer and use it in GitHub Desktop.
#include <range/v3/all.hpp>
#include <vector>
#include <array>
#include <iostream>
using std::cout;
using std::endl;
using namespace ranges;
auto is_six = [](int i) -> bool { return i == 6; };
auto doub = [](int i) -> int { return 2 * i; };
int main() {
std::vector<int> v { 6, 2, 3, 4, 5, 6 };
auto c = count_if( v, is_six );
cout << "count-sixes: " << c << endl;
auto s = accumulate( v, 0 );
cout << "sum-vetor: " << s << endl;
auto e = find_if( view::ints(1) | view::transform(doub), is_six );
cout << "find-six: " << *e.get_unsafe() << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment