Json.move
template<typename T, typename D = Nul>
requires convertible<T> || convertible_map<T, D> || convertible_array<T, D>
[[nodiscard]]
T move( D default_range_elem = D{} );
Attempts to move-convert internal data to type T
, throwing on failure.
Extensive compile-time checks eliminate incompatible conversions during compilation.
Runtime conversion may still fail due to JSON's dynamic typing nature.
Warning: Successful move operations will leave the source object empty, even if the result isn't used.
Recommended to reset source object after moving.
Move Conversion Rules
- Nul → Nul
- Obj → Obj (moved)
- Arr → Arr (moved)
- Str → Str (moved)
- Bol → Bol (copied)
- Num → Enum (rounded)
- Num → Integer (rounded)
- Num → Floating-point
- Any → Json-constructible types (move preferred)
- Obj → Implicitly convertible (move preferred)
- Arr → Implicitly convertible (move preferred)
- Str → Implicitly convertible (move preferred)
- Num → Implicitly convertible
- Bol → Implicitly convertible
- Nul → Implicitly convertible (except bool)
- Obj → Convertible key-value types (element-wise, move preferred)
- Arr → Convertible container types (element-wise, move preferred)
- Throws std::runtime_error
Parameters
T
: Target typedefault_range_elem
: Fallback for failed element conversions (array/object only)
Exception Safety
Throws on Move construction failures.
Complexity
- O(1) for movable types
- O(n) for element-wise conversions
Key Notes: - Source object becomes Nul after successful move - Prefers move semantics where possible - Numeric/bool conversions remain copy operations
Version
Since v3.0.0 .