Replies: 5 comments 1 reply
-
look at this example: |
Beta Was this translation helpful? Give feedback.
-
After a bit more thinking, and looking at Iguana code... do I just need to implement |
Beta Was this translation helpful? Give feedback.
-
...I mean extend |
Beta Was this translation helpful? Give feedback.
-
You can extend to support your type like this: you need to define your custom to_json/from_json function. |
Beta Was this translation helpful? Give feedback.
-
More simpler way, add YLT_REFL for template VecArray : template<typename T, size_t N>
struct VecArray {
std::array<T, N> els_;
size_t size_ = 0;
T& operator[](int index) { return els_[index]; }
size_t size() const { return size_; }
size_t capacity() const { return N; }
void push_back(const T& el) { els_[size_++] = std::move(el); }
YLT_REFL(VecArray, els_, size_);
};
struct Data {
VecArray<int, 10> int_vals_;
VecArray<float, 20> float_vals_;
};
YLT_REFL(Data, int_vals_, float_vals_);
int main() {
Data data;
data.int_vals_.push_back(1);
data.int_vals_.push_back(2);
data.int_vals_.push_back(3);
data.float_vals_.push_back(4.56);
std::string s;
iguana::to_json(data, s);
std::cout << s << std::endl;
} output:
|
Beta Was this translation helpful? Give feedback.
-
Hi - I'm not an expert C++ coder so apologies if I'm missing something obvious.
I have a class which wraps std::array to give it more std::vector-like functionality, and I want to serialize/deserialize it to/from json files. Please can someone help me get started - what do I need to add, and where?
Cheers
John
Beta Was this translation helpful? Give feedback.
All reactions