Summary
Add native support for reflecting and (de)serializing std::atomic<T> fields, where T is already supported by reflect-cpp.
Motivation
In modern C++ codebases, std::atomic<T> is commonly used for counters, state flags, and progress indicators that still need to be reflected (e.g. JSON serialization, config snapshots, telemetry, IPC payloads).
Currently, structs containing std::atomic<T> fields are not reflectable without custom wrappers or manual conversion.
Proposed Behavior
- Treat
std::atomic<T> as reflectable when T is reflectable.
- Serialization should read via
load(std::memory_order_relaxed).
- Deserialization should write via
store(value, std::memory_order_relaxed).
- No additional synchronization guarantees beyond atomicity are required.
Example
struct Stats {
std::atomic<std::uint64_t> bytes_downloaded;
std::atomic<bool> finished;
};
Expected behavior:
bytes_downloaded and finished serialize as their underlying values.
- Deserialization updates the atomics via
store.
Notes
- This mirrors how many serialization libraries treat atomics (as value wrappers).
- Memory ordering can be relaxed, as reflection is value-oriented, not synchronization-oriented.
Summary
Add native support for reflecting and (de)serializing
std::atomic<T>fields, whereTis already supported by reflect-cpp.Motivation
In modern C++ codebases,
std::atomic<T>is commonly used for counters, state flags, and progress indicators that still need to be reflected (e.g. JSON serialization, config snapshots, telemetry, IPC payloads).Currently, structs containing
std::atomic<T>fields are not reflectable without custom wrappers or manual conversion.Proposed Behavior
std::atomic<T>as reflectable whenTis reflectable.load(std::memory_order_relaxed).store(value, std::memory_order_relaxed).Example
Expected behavior:
bytes_downloadedandfinishedserialize as their underlying values.store.Notes