[Question] Using custom std::vector<Point> class
sidazhang opened this issue · comments
In the documentation, there was an example of how to using a custom point class.
Is there an example that show cases a custom polygon class (i.e. std::vector)
My use case is that I have a flat array float*
in memory. Which looks like this
float1, float2, float3, float4 ...
x0 y0 x1 y2
It would be great to be able to write a container class that accesses the underlying data rather than copying into a std::vector<Point>
It's possible by writing a wrapper class for your array, which implements the requirements of container.
A simple non-generic wrapper implementation would probably start as something like
class PointArrayView {
private:
Point* data;
std::size_t length;
public:
std::size_t size() const;
bool empty() const;
Point& operator[] (const int index);
}
I might write a full example when I have time, even though this is more of a general c++ programming question. You might also look up "array_view" implementations on google which are the same thing but with templates.