Skip to content

Support std::atomic<T> fields #575

@RampantDespair

Description

@RampantDespair

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions