range-v3

Sum vector with range-v3

喜欢而已 提交于 2020-07-22 04:16:45
问题 I need to sum up some vectors; that is, I want to sum the nth elements of every vector and make a new vector with the result. (I've already ensured that the input vectors are all the same size.) I'd like to do this with the excellent range-v3 library. I've tried this: // This file is a "Hello, world!" in C++ language by GCC for wandbox. #include <iostream> #include <cstdlib> #include <vector> #include <cmath> #include <map> #include <range/v3/all.hpp> int main() { std::cout << "Hello, Wandbox

Using ranges::view::iota in parallel algorithms

烂漫一生 提交于 2020-06-25 09:40:07
问题 Since there is no index based parallel for algorithm in c++17, I'm wondering if ranges::view::iota can be used in combination with std::for_each to emulate that. That is: using namespace std; constexpr int N= 10'000'000; ranges::iota_view indices(0,N); vector<int> v(N); for_each(execution::par_unseq,indices.begin(),indices.end(),[&](int i) { v[i]= i; }); iota_view seems to provide random access for appropriate types ([range.iota.iterator]): iota_view<I, Bound>::iterator::iterator_category is

Why is std::back_inserter_iterator not WeaklyIncrementable in RangeV3?

荒凉一梦 提交于 2020-06-11 07:34:12
问题 To my surprise this Concept-like assertion fails in RangeV3. #include<vector> #include<range/v3/algorithm/copy.hpp> int main(){ static_assert(ranges::WeaklyIncrementable<std::back_insert_iterator<std::vector<double> >>()); } Why is that? This, among other things means that I cannot use the ranges::copy algorithm as I use to do with std::copy . std::vector<double> w(100); std::vector<double> v; ranges::copy( begin(w), end(w), std:back_inserter(v) ); // compilation error, concept not fulfilled.

How to zip vector of vector with range-v3

瘦欲@ 提交于 2020-05-29 08:44:24
问题 (This is a follow-on to Sum vector with range-v3) If I have two (or more) vectors, I can zip them together with range-v3 like this: std::vector< int > v1{1,1,1}; std::vector< int > v2{2,2,2}; auto v = ranges::views::zip( v1, v2 ) | ranges::views::transform( ... ); This works well, but in practice, I don't have explicit vectors, but I do have a vector of vectors. I'd like to do the following, but it doesn't give the same result. (In fact, I'm not sure what the result is, and I don't know how

How to zip vector of vector with range-v3

橙三吉。 提交于 2020-05-29 08:44:09
问题 (This is a follow-on to Sum vector with range-v3) If I have two (or more) vectors, I can zip them together with range-v3 like this: std::vector< int > v1{1,1,1}; std::vector< int > v2{2,2,2}; auto v = ranges::views::zip( v1, v2 ) | ranges::views::transform( ... ); This works well, but in practice, I don't have explicit vectors, but I do have a vector of vectors. I'd like to do the following, but it doesn't give the same result. (In fact, I'm not sure what the result is, and I don't know how

How to zip vector of vector with range-v3

十年热恋 提交于 2020-05-29 08:42:37
问题 (This is a follow-on to Sum vector with range-v3) If I have two (or more) vectors, I can zip them together with range-v3 like this: std::vector< int > v1{1,1,1}; std::vector< int > v2{2,2,2}; auto v = ranges::views::zip( v1, v2 ) | ranges::views::transform( ... ); This works well, but in practice, I don't have explicit vectors, but I do have a vector of vectors. I'd like to do the following, but it doesn't give the same result. (In fact, I'm not sure what the result is, and I don't know how

Using range-v3 to read comma separated list of numbers

半腔热情 提交于 2020-01-24 09:28:46
问题 I'd like to use Ranges (I use range-v3 implementation) to read a input stream that is a comma separated list of numbers. That is trivial to do without ranges but... This is what I thought was the straight-forward way to solve it: auto input = std::istringstream("42,314,11,0,14,-5,37"); auto ints = ranges::istream_view<int>(input) | ranges::view::split(","); for (int i : ints) { std::cout << i << std::endl; } But this fails to compile. I've tried a number of variations of this but nothing seem