Deseralizing a custom Vec class #501
-
As part of a project, I've had to write my own basic vector math class, and I want to find some way to deseralize JSON directly to it. Reading the documentation, I see:
But I'm not sure what this looks like in practice (or what I would need to implement to support this). My Vec class at the moment looks like this: template<size_t N>
class Vec {
public:
Vec() = default;
explicit Vec(float v) {
_values.fill(v);
}
Vec(const std::array<float, N> &values) : _values{values} {}
template<typename... Args>
explicit Vec(Args... args) : _values{args...} {}
// ...
protected:
std::array<float, N> _values;
}; and I'm trying to deseralize JSON like this (note the mix of int and float literals)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For a static vector like this, I think you just need to satisfy this concept: template <class T>
concept range = requires(T& t) {
requires !std::same_as<void, decltype(t.begin())>;
requires !std::same_as<void, decltype(t.end())>;
requires std::input_iterator<decltype(t.begin())>;
};
So, you need You could just return the iterators from the std::array you are using. |
Beta Was this translation helpful? Give feedback.
For a static vector like this, I think you just need to satisfy this concept:
So, you need
begin
andend
iterators to your vector.You could just return the iterators from the std::array you are using.