diff options
Diffstat (limited to 'nihil.ucl/integer.ccm')
| -rw-r--r-- | nihil.ucl/integer.ccm | 65 |
1 files changed, 10 insertions, 55 deletions
diff --git a/nihil.ucl/integer.ccm b/nihil.ucl/integer.ccm index 482a716..e43ae8b 100644 --- a/nihil.ucl/integer.ccm +++ b/nihil.ucl/integer.ccm @@ -4,10 +4,9 @@ module; -#include <cassert> +#include <compare> #include <cstdint> #include <cstdlib> -#include <string> #include <ucl.h> @@ -22,72 +21,28 @@ export struct integer final : object { inline static constexpr object_type ucl_type = object_type::integer; // Create a new integer from a UCL object. - integer(ref_t, ::ucl_object_t const *uobj) - : object(nihil::ucl::ref, uobj) - { - if (type() != ucl_type) - throw type_mismatch(ucl_type, type()); - } - - integer(noref_t, ::ucl_object_t *uobj) - : object(noref, uobj) - { - if (type() != ucl_type) - throw type_mismatch(ucl_type, type()); - } + integer(ref_t, ::ucl_object_t const *uobj); + integer(noref_t, ::ucl_object_t *uobj); // Create a new default-initialised integer. - integer() - : integer(0) - {} + integer(); // Create a new integer from a value. - explicit integer(contained_type value) - : object(noref, ::ucl_object_fromint(value)) - { - if (_object == nullptr) - throw error("failed to create UCL object"); - } + explicit integer(contained_type value); // Return the value of this object. - auto value(this integer const &self) -> contained_type - { - auto v = contained_type{}; - auto const *uobj = self.get_ucl_object(); - - if (::ucl_object_toint_safe(uobj, &v)) - return v; - - std::abort(); - } + auto value(this integer const &self) -> contained_type; }; /* * Comparison operators. */ -export auto operator== (integer const &a, integer const &b) - -> bool -{ - return a.value() == b.value(); -} - +export auto operator== (integer const &a, integer const &b) -> bool; +export auto operator== (integer const &a, integer::contained_type b) -> bool; export auto operator<=> (integer const &a, integer const &b) - -> std::strong_ordering -{ - return a.value() <=> b.value(); -} - -export auto operator== (integer const &a, integer::contained_type b) - -> bool -{ - return a.value() == b; -} - + -> std::strong_ordering; export auto operator<=> (integer const &a, integer::contained_type b) - -> std::strong_ordering -{ - return a.value() <=> b; -} + -> std::strong_ordering; } // namespace nihil::ucl |
