June 2018
Intermediate to advanced
348 pages
8h 45m
English
To get started with the Streams library, let's write a small program to generate a Stream of numbers and compute the square of the first ten numbers:
//--------- Streams_First.cpp
#include "Stream.h"
using namespace std;
using namespace Stream;
using namespace Stream::op;
int main(){
//-------- counter(n) - Generate a series of value
//-------- Map (Apply a Lambda)
//-------- limit(n) -- Take first ten items
//-------- Sum -- aggregate
int total = MakeStream::counter(1)
| map_([] (int x) { return x * x; } // Apply square on each elements
| limit(10) //take first ten elements
| sum(); // sum the Stream contents Streams::op::sum //----------- print the result cout << total << endl; }
The previous code snippet generates ...
Read now
Unlock full access