Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLartians authored May 8, 2019
1 parent 46f1f55 commit 0f1dd65
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,53 @@

# EasyIterator

Work in progress: simple C++ iterator creation
EasyIterator aims to be a zero-cost C++17 iterator library that simplifies iterator creation.
It adds well-known iterators from other languages to C++, such as `range`, `zip` and `enumerate`.

## Example

### Iteration

```cpp
using namespace easy_iterator;

std::vector<int> integers(10);
std::vector<std::string> strings(integers.size());

for (auto i: range(integers.size())) {
integers[i] = i*i;
}

for (auto [i, v, s]: zip(range(integers.size()), integers, strings)) {
s = std::to_string(i) + "^2 = " + std::to_string(v);
}

for (auto [i, s]: enumerate(strings)) {
std::cout << "strings[" << i << "] = \"" << s << "\"" << std::endl;
}
```
### Simple iterator creation
```cpp
struct Fibonacci {
unsigned current = 0;
unsigned next = 1;
void advance() {
auto tmp = next;
next += current;
current = tmp;
return true;
}
unsigned value() {
return current;
}
};
for (auto [i,v]: enumerate(MakeIterable<Fibonacci>())){
std::cout << "Fib_" << i << "\t= " << v << std::endl;
if (i > 10) break;
}
```

0 comments on commit 0f1dd65

Please sign in to comment.