Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Chrono
- CustomTab
- SHA512
- coroutines
- design pattern
- sha256
- SHA1
- async
- traits
- ranges
- Scala
- template
- Observer
- go
- Clojure
- RAII
- Android
- c++
- sprintf
- WebView
- program
- kotlin
- Functional
- haskell
- type_traits
- ChromeTab
- Reflect
- web
- stringprintf
- AES
Archives
- Today
- Total
프로그래밍 검색 블로그
C++ ranges view::for_each 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <iostream> #include <vector> #include <range/v3/view.hpp> using namespace std; using namespace ranges; int main(){ vector<int> v = view::iota(0, 10) | view::for_each([](int e){ return yield(e * 2); }); cout << view::all(v) << endl; } | cs |
생각한 그대로의 for_each 사용법이다.
다만 ranges는 기본적으로 지연처리를 해서 반환값에 yield가 붙은것 정도
for_each같은 경우는 하스켈의 bind연산자를 가져와서 >>= 를 함수에 붙이는것 또한 가능하다
1 2 3 | vector<int> v = view::iota(0, 10) >>= [](int e){ return yield(e * 2); }; | cs |
기본적으로 ranges는 모두 가능하며
1 2 3 4 | vector<int> c = {1,2,3,4,5}; vector<int> v = c >>= [](int e){ return yield(e * 2); }; | cs |
1 2 3 4 5 6 7 | map<int,int> c = { {1,2}, {3,4} }; vector<int> v = c >>= [](const std::pair<int,int>& e){ return yield(e.second * 2); }; | cs |
기존 stl만 가지고도 가능했다.
'C++ ranges' 카테고리의 다른 글
C++ ranges view::take (0) | 2017.10.08 |
---|---|
C++ ranges yield_if (0) | 2017.10.08 |
C++ ranges view::filter (0) | 2017.10.07 |
C++ ranges view::iota (0) | 2017.10.07 |
C++ ranges view::all (0) | 2017.10.07 |
Comments