From d7aae40365365d0ef79ea58f14d76abcc2a64af8 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 7 Feb 2025 01:06:23 +0900 Subject: [PATCH 1/2] feat: add compare operators to spec --- include/toml11/spec.hpp | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/include/toml11/spec.hpp b/include/toml11/spec.hpp index ca0a996..4878ad3 100644 --- a/include/toml11/spec.hpp +++ b/include/toml11/spec.hpp @@ -1,8 +1,10 @@ #ifndef TOML11_SPEC_HPP #define TOML11_SPEC_HPP +#include #include #include +#include #include @@ -117,5 +119,50 @@ struct spec bool ext_null_value; // allow `null` as a value }; +namespace detail +{ +inline std::pair> +to_tuple(const spec& s) noexcept +{ + return std::make_pair(std::cref(s.version), std::array{{ + s.v1_1_0_allow_control_characters_in_comments, + s.v1_1_0_allow_newlines_in_inline_tables, + s.v1_1_0_allow_trailing_comma_in_inline_tables, + s.v1_1_0_allow_non_english_in_bare_keys, + s.v1_1_0_add_escape_sequence_e, + s.v1_1_0_add_escape_sequence_x, + s.v1_1_0_make_seconds_optional, + s.ext_hex_float, + s.ext_num_suffix, + s.ext_null_value + }}); +} +} // detail + +inline bool operator==(const spec& lhs, const spec& rhs) noexcept +{ + return detail::to_tuple(lhs) == detail::to_tuple(rhs); +} +inline bool operator!=(const spec& lhs, const spec& rhs) noexcept +{ + return detail::to_tuple(lhs) != detail::to_tuple(rhs); +} +inline bool operator< (const spec& lhs, const spec& rhs) noexcept +{ + return detail::to_tuple(lhs) < detail::to_tuple(rhs); +} +inline bool operator<=(const spec& lhs, const spec& rhs) noexcept +{ + return detail::to_tuple(lhs) <= detail::to_tuple(rhs); +} +inline bool operator> (const spec& lhs, const spec& rhs) noexcept +{ + return detail::to_tuple(lhs) > detail::to_tuple(rhs); +} +inline bool operator>=(const spec& lhs, const spec& rhs) noexcept +{ + return detail::to_tuple(lhs) >= detail::to_tuple(rhs); +} + } // namespace toml #endif // TOML11_SPEC_HPP From dda740281e3a6c2f622b9713418cdf960eb77d16 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 7 Feb 2025 01:26:58 +0900 Subject: [PATCH 2/2] fix: add missing include file --- include/toml11/spec.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/toml11/spec.hpp b/include/toml11/spec.hpp index 4878ad3..df9f3d7 100644 --- a/include/toml11/spec.hpp +++ b/include/toml11/spec.hpp @@ -2,6 +2,7 @@ #define TOML11_SPEC_HPP #include +#include #include #include #include