mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-28 22:06:19 +08:00
Only for serialization - similarly to pointers, this should not be used for deserialization. As discussed https://github.com/getml/reflect-cpp/pull/20#issuecomment-1857491501 this requires changing the implementation of bind_to_tuple, since std::ref() collapses on a std::reference_wrapper.
36 lines
837 B
C++
36 lines
837 B
C++
#include "test_std_ref.hpp"
|
|
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <rfl.hpp>
|
|
#include <rfl/json.hpp>
|
|
#include <source_location>
|
|
#include <string>
|
|
|
|
namespace test_std_ref {
|
|
|
|
struct StdRefStruct {
|
|
std::reference_wrapper<int> a;
|
|
};
|
|
|
|
void test() {
|
|
std::cout << std::source_location::current().function_name() << std::endl;
|
|
|
|
int i = 10;
|
|
StdRefStruct struct_ = {.a = std::ref(i)};
|
|
|
|
const auto json_string = rfl::json::write(struct_);
|
|
const std::string& expected = R"({"a":10})";
|
|
if (json_string != expected) {
|
|
std::cout << "Test failed on write. Expected:" << std::endl
|
|
<< expected << std::endl
|
|
<< "Got: " << std::endl
|
|
<< json_string << std::endl
|
|
<< std::endl;
|
|
return;
|
|
}
|
|
std::cout << "OK" << std::endl << std::endl;
|
|
}
|
|
|
|
} // namespace test_std_ref
|