diff --git a/include/rfl/parsing/Parser_array.hpp b/include/rfl/parsing/Parser_array.hpp index eff72956..fd762154 100644 --- a/include/rfl/parsing/Parser_array.hpp +++ b/include/rfl/parsing/Parser_array.hpp @@ -60,7 +60,7 @@ struct Parser> { AlreadyExtracted&&... _already_extracted) noexcept { constexpr size_t i = sizeof...(AlreadyExtracted); if constexpr (i == _size) { - return std::array({std::move(_already_extracted)...}); + return std::array{std::move(_already_extracted)...}; } else { const auto extract_next = [&](auto&& new_entry) { return extract_field_by_field(_r, std::move(_vec), diff --git a/tests/json/test_c_array_class1.cpp b/tests/json/test_c_array_class1.cpp new file mode 100644 index 00000000..91de3284 --- /dev/null +++ b/tests/json/test_c_array_class1.cpp @@ -0,0 +1,28 @@ +#include "test_c_array_class1.hpp" + +#include +#include +#include + +#include "rfl.hpp" +#include "rfl/json.hpp" +#include "write_and_read.hpp" + +namespace test_c_array_class1 { + +struct Test1 { + std::vector classes[3]; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + + Test1 test1 = {.classes = {{"Little A", "Little B", "Little C"}, + {"BIG A", "BIG B", "BIG C"}, + {"??", "$%", "#@"}}}; + write_and_read( + test1, + R"({"classes":[["Little A","Little B","Little C"],["BIG A","BIG B","BIG C"],["??","$%","#@"]]})"); +} + +} // namespace test_c_array_class1 diff --git a/tests/json/test_c_array_class1.hpp b/tests/json/test_c_array_class1.hpp new file mode 100644 index 00000000..8bb514e0 --- /dev/null +++ b/tests/json/test_c_array_class1.hpp @@ -0,0 +1,5 @@ +namespace test_c_array_class1 { + +void test(); + +} diff --git a/tests/json/test_c_array_class2.cpp b/tests/json/test_c_array_class2.cpp new file mode 100644 index 00000000..e61134ef --- /dev/null +++ b/tests/json/test_c_array_class2.cpp @@ -0,0 +1,32 @@ +#include "test_c_array_class2.hpp" + +#include +#include +#include + +#include "rfl.hpp" +#include "rfl/json.hpp" +#include "write_and_read.hpp" + +namespace test_c_array_class2 { + +struct Test2 { + int multi_dimension_arr[2][2][2][2]; + std::string s; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + + Test2 test2; + for (int i = 0; i < 1 << 4; i++) { + test2.multi_dimension_arr[i >> 3 & 1][i >> 2 & 1][i >> 1 & 1][i >> 0 & 1] = i; + } + test2.s = "Hello, world!"; + + write_and_read( + test2, + R"({"multi_dimension_arr":[[[[0,1],[2,3]],[[4,5],[6,7]]],[[[8,9],[10,11]],[[12,13],[14,15]]]],"s":"Hello, world!"})"); +} + +} // namespace test_c_array diff --git a/tests/json/test_c_array_class2.hpp b/tests/json/test_c_array_class2.hpp new file mode 100644 index 00000000..9e082e55 --- /dev/null +++ b/tests/json/test_c_array_class2.hpp @@ -0,0 +1,5 @@ +namespace test_c_array_class2 { + +void test(); + +} diff --git a/tests/json/test_c_array_class3.cpp b/tests/json/test_c_array_class3.cpp new file mode 100644 index 00000000..b49ce329 --- /dev/null +++ b/tests/json/test_c_array_class3.cpp @@ -0,0 +1,21 @@ +#include "test_c_array_class3.hpp" + +#include +#include + +#include "rfl.hpp" +#include "rfl/json.hpp" +#include "write_and_read.hpp" + +namespace test_c_array_class3 { + +using Test3 = std::array[3]; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + + Test3 test3 = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + write_and_read(test3, "[[1,2,3],[4,5,6],[7,8,9]]"); +} + +} // namespace test_c_array diff --git a/tests/json/test_c_array_class3.hpp b/tests/json/test_c_array_class3.hpp new file mode 100644 index 00000000..9a2931da --- /dev/null +++ b/tests/json/test_c_array_class3.hpp @@ -0,0 +1,5 @@ +namespace test_c_array_class3 { + +void test(); + +} diff --git a/tests/json/test_c_array_class4.cpp b/tests/json/test_c_array_class4.cpp new file mode 100644 index 00000000..8ba85777 --- /dev/null +++ b/tests/json/test_c_array_class4.cpp @@ -0,0 +1,26 @@ +#include "test_c_array_class4.hpp" + +#include +#include + +#include "rfl.hpp" +#include "rfl/json.hpp" +#include "write_and_read.hpp" + +namespace test_c_array_class4 { + +struct Test4 { + int a[3]; + int b[3]; + int c[2][2]; +}; + +void test() { + std::cout << std::source_location::current().function_name() << std::endl; + + Test4 test4 = {.a = {1, 2, 3}, .b = {4, 5, 6}, .c = {{7, 8}, {9, 10}}}; + + write_and_read(test4, R"({"a":[1,2,3],"b":[4,5,6],"c":[[7,8],[9,10]]})"); +} + +} // namespace test_c_array_class4 diff --git a/tests/json/test_c_array_class4.hpp b/tests/json/test_c_array_class4.hpp new file mode 100644 index 00000000..32857ec4 --- /dev/null +++ b/tests/json/test_c_array_class4.hpp @@ -0,0 +1,5 @@ +namespace test_c_array_class4 { + +void test(); + +} diff --git a/tests/json/tests.cpp b/tests/json/tests.cpp index 839744da..b3471bc0 100644 --- a/tests/json/tests.cpp +++ b/tests/json/tests.cpp @@ -8,6 +8,10 @@ #include "test_as2.hpp" #include "test_as_flatten.hpp" #include "test_box.hpp" +#include "test_c_array_class1.hpp" +#include "test_c_array_class2.hpp" +#include "test_c_array_class3.hpp" +#include "test_c_array_class4.hpp" #include "test_custom_class1.hpp" #include "test_custom_class2.hpp" #include "test_custom_class3.hpp" @@ -135,5 +139,9 @@ int main() { test_meta_fields::test(); + test_c_array_class1::test(); + test_c_array_class2::test(); + test_c_array_class3::test(); + test_c_array_class4::test(); return 0; }