boost-range

How to create a Boost.Range that hides multiple layers of vectors and exposes it as a single Range?

醉酒当歌 提交于 2019-12-07 10:08:37
问题 I have a legacy class hierarchy which I can not modify. Because of requirements of an external library, I need to define Boost.Ranges for the Line and Ring, where both only expose the points in a single run (i.e. it should, both for Line and Ring, be a Boost.Range of Points). Pseudo-code to illustrate: Line l1 = Line{{1.0,2.0},{3.0,4.0},{5.0,6.0}} // init Line with three Points Line l2 = Line{{7.0,8.0},{9.0,10.0},{11.0,12.0}} // init Line with three Points auto lit = boost::begin(l1); //

Why is ADL not working with Boost.Range?

拥有回忆 提交于 2019-12-04 02:53:45
问题 Considering: #include <cassert> #include <boost/range/irange.hpp> #include <boost/range/algorithm.hpp> int main() { auto range = boost::irange(1, 4); assert(boost::find(range, 4) == end(range)); } Live Clang demo Live GCC demo this gives: main.cpp:8:37: error: use of undeclared identifier 'end' Considering that if you write using boost::end; it works just fine, which implies that boost::end is visible: Why is ADL not working and finding boost::end in the expression end(range) ? And if it's

Why is ADL not working with Boost.Range?

一笑奈何 提交于 2019-12-01 16:14:47
Considering: #include <cassert> #include <boost/range/irange.hpp> #include <boost/range/algorithm.hpp> int main() { auto range = boost::irange(1, 4); assert(boost::find(range, 4) == end(range)); } Live Clang demo Live GCC demo this gives: main.cpp:8:37: error: use of undeclared identifier 'end' Considering that if you write using boost::end; it works just fine , which implies that boost::end is visible: Why is ADL not working and finding boost::end in the expression end(range) ? And if it's intentional, what's the rationale behind it? To be clear, the expected result would be similar to what

boost transform iterator and c++11 lambda

落花浮王杯 提交于 2019-11-30 14:55:49
问题 I'm trying to use boost::adaptors::transformed by providing a c++0x lambda to the adaptor. The following code does not compile. I'm using g++ 4.6.2 with boost 1.48. #include <iostream> #include <vector> #include <boost/range/adaptors.hpp> #include <boost/range/algorithm.hpp> using namespace std; namespace br = boost::range; namespace badpt = boost::adaptors; int main() { vector<int> a = {0,3,1,}; vector<int> b = {100,200,300,400}; auto my_ftor = [&b](int r)->int{return b[r];}; cout<<*br::max

Using Boost adaptors with C++11 lambdas

梦想与她 提交于 2019-11-27 08:53:34
I tried to compile this code: #include <boost/range/adaptors.hpp> #include <boost/range/algorithm.hpp> #include <vector> int main() { std::vector<int> v{ 1,5,4,2,8,5,3,7,9 }; std::cout << *boost::min_element(v | boost::adaptors::transformed( [](int i) { return -i; })) << std::endl; return 0; } The compilation failed with the following error message (after a long template instantiation novel): /usr/local/include/boost/iterator/transform_iterator.hpp:84:26: error: use of deleted function ‘main()::<lambda(int)>::<lambda>()’ ../main.cpp:12:5: error: a lambda closure type has a deleted default

Using Boost adaptors with C++11 lambdas

岁酱吖の 提交于 2019-11-26 14:21:28
问题 I tried to compile this code: #include <boost/range/adaptors.hpp> #include <boost/range/algorithm.hpp> #include <vector> int main() { std::vector<int> v{ 1,5,4,2,8,5,3,7,9 }; std::cout << *boost::min_element(v | boost::adaptors::transformed( [](int i) { return -i; })) << std::endl; return 0; } The compilation failed with the following error message (after a long template instantiation novel): /usr/local/include/boost/iterator/transform_iterator.hpp:84:26: error: use of deleted function ‘main(