41#include <glaze/glaze.hpp>
48#include "../attributes.hpp"
51namespace morph::util {
59template <
typename T, morph::detail::FixedString Tag>
65 constexpr Tagged() noexcept(std::is_nothrow_default_constructible_v<T>) = default;
69 constexpr explicit
Tagged(T wrapped) noexcept(std::is_nothrow_move_constructible_v<T>)
70 :
value{std::move(wrapped)} {}
74 [[nodiscard]]
static constexpr std::string_view
tag() noexcept {
return Tag.view(); }
78 [[nodiscard]]
constexpr bool hasValue() const noexcept {
return true; }
83 [[nodiscard]]
constexpr const T&
get() const noexcept MORPH_LIFETIMEBOUND {
return value; }
90 [[nodiscard]]
constexpr const T&
operator*() const noexcept MORPH_LIFETIMEBOUND {
return value; }
96 requires std::equality_comparable<T>
103 requires std::three_way_comparable<T>
113template <
typename U, morph::detail::FixedString Tag>
126template <
typename T, morph::detail::FixedString Tag>
133 static constexpr std::string_view name = Tag.view();
136namespace glz::detail {
143template <
typename T, morph::detail::FixedString Tag>
144struct to_json_schema<morph::util::Tagged<T, Tag>> {
150 static void op(
auto& outSchema,
auto& defs) {
151 to_json_schema<T>::template op<Opts>(outSchema, defs);
173template <
typename T, morph::detail::FixedString Tag>
180 static std::string_view
name() {
181 static const std::string kName =
"tagged." + std::string{Tag.view()};
Shared compile-time, NTTP-capable fixed string.
Opt-in, compiler-independent shape tag for a type with a custom Glaze codec.
static std::string_view name()
This type's stable shape name, e.g. "tagged.acct".
T Inner
The wrapped type, rendered inside this tag.
Declares a stable shape tag for a type T whose JSON shape payloadShape cannot decompose.
An opaque, type-safe newtype wrapping a protocol scalar T, distinguished at compile time by the strin...
constexpr Tagged() noexcept(std::is_nothrow_default_constructible_v< T >)=default
Constructs the default-valued state (T{}).
constexpr const T & get() const noexcept
Read access to the wrapped value.
constexpr const T & operator*() const noexcept
Unchecked access to the wrapped value, mirroring Quantity's and Choice's operator* for consistency ac...
constexpr auto operator<=>(const Tagged &other) const noexcept(noexcept(value<=> other.value))=default
Three-way comparison on the wrapped value, when T supports it.
constexpr bool hasValue() const noexcept
Always true: Tagged is a required scalar, never empty.
T value
The underlying scalar value.
constexpr bool operator==(const Tagged &other) const noexcept(noexcept(value==other.value))=default
Equality on the wrapped value.
static constexpr std::string_view tag() noexcept
The compile-time tag naming this newtype.
Trait: is T some Tagged<...>?
constexpr bool isTagged
true when T (cvref-stripped) is a morph::util::Tagged.