-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Description
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 whenTis 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_downloadedandfinishedserialize 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.
liuzicheng1987
Metadata
Metadata
Assignees
Labels
No labels