/* * This source code is released into the public domain. */ module; #include #include #include #include #include #include #include export module nihil.ucl:boolean; import :object; namespace nihil::ucl { export struct boolean final : object { using contained_type = bool; inline static constexpr object_type ucl_type = object_type::boolean; /* * Create a boolean holding the value false. Throws std::system_error * on failure. */ boolean(); /* * Create a boolean holding a specific value. Throws std::system_error * on failure. */ explicit boolean(bool); /* * Create a new boolean from a UCL object. Throws type_mismatch * on failure. */ boolean(ref_t, ::ucl_object_t const *uobj); boolean(noref_t, ::ucl_object_t *uobj); // Return this object's value. auto value(this boolean const &self) -> contained_type; }; /* * Boolean constructors. These return an error instead of throwing. */ export [[nodiscard]] auto make_boolean(boolean::contained_type = false) -> std::expected; /* * Comparison operators. */ export auto operator== (boolean const &a, boolean const &b) -> bool; export auto operator== (boolean const &a, boolean::contained_type b) -> bool; export auto operator<=> (boolean const &a, boolean const &b) -> std::strong_ordering; export auto operator<=> (boolean const &a, boolean::contained_type b) -> std::strong_ordering; } // namespace nihil::ucl /* * std::formatter for a boolean. This provides the same format operations * as std::formatter. */ export template<> struct std::formatter { std::formatter base_formatter; template constexpr ParseContext::iterator parse(ParseContext& ctx) { return base_formatter.parse(ctx); } template FmtContext::iterator format(nihil::ucl::boolean const &o, FmtContext& ctx) const { return base_formatter.format(o.value(), ctx); } };