0

I want to use range-v3 to enumerate a range. The range is produce by CGAL using the CGAL::Surface_mesh<K>::faces() function, which returns a range for the faces in the mesh.

However, range-v3 can't attach views to an rvalue range, so I can't do mesh.faces() | ranges::views::enumerate

I can store the result of mesh.faces() into a temporary and then use that, but would be cool to be able to do this in one line.

Is there anyway to do this?

jjcasmar
  • 1,387
  • 1
  • 18
  • 30

1 Answers1

0

Let me demonstrate on a simple example

#include <vector>
#include <range/v3/all.hpp>
using namespace ranges;
static struct help_t{} help;
template<class C>
auto operator|(C const&c, help_t){return views::all(c);}
int main(){
  std::vector<int>{1,2,3} | help | views::enumerate;
}

The vector is only destructed after the 2 calls to operator|. This hides the danger from range-v3, which seems ok in this case... If they don't provide something like that in range-v3 (do they?), even with a scary name, I'd still be wary of it.

Marc Glisse
  • 7,550
  • 2
  • 30
  • 53