diff --git a/include/iris/x4/core/char_traits.hpp b/include/iris/x4/core/char_traits.hpp index 19ad29650..793fff880 100644 --- a/include/iris/x4/core/char_traits.hpp +++ b/include/iris/x4/core/char_traits.hpp @@ -8,6 +8,9 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ================================================_==============================*/ +// This header is intended for inclusion by user-facing, non-parser headers. +// Do not add includes specific to X4's parser implementation here. + #include #include diff --git a/include/iris/x4/core/expectation.hpp b/include/iris/x4/core/expectation.hpp index 19f9ea6bc..c1fd0e232 100644 --- a/include/iris/x4/core/expectation.hpp +++ b/include/iris/x4/core/expectation.hpp @@ -12,16 +12,14 @@ #include +#include // export #include // for `x4::what` #include #include -#include #include #include -#include - namespace iris::x4 { namespace contexts { @@ -33,76 +31,6 @@ struct expectation_failure } // contexts -using expectation_failure_tag [[deprecated("Use `x4::contexts::expectation_failure`")]] = contexts::expectation_failure; - -template -struct expectation_failure -{ - constexpr expectation_failure() = default; - - template - requires std::is_constructible_v - constexpr expectation_failure(It where, WhichT&& which) - noexcept(std::is_nothrow_copy_constructible_v && std::is_nothrow_constructible_v) - : where_(where) - , which_(std::forward(which)) - { - if (which_.empty()) { - which_ = "(unknown location)"; - } - } - - [[nodiscard]] - constexpr It const& where() const noexcept - { - assert(this->has_value()); - return where_; - } - - [[nodiscard]] - constexpr std::string const& which() const noexcept - { - assert(this->has_value()); - return which_; - } - - constexpr void clear() noexcept - { - which_.clear(); - } - - template - requires std::is_constructible_v - constexpr void emplace(It where, WhichT&& which) - noexcept(std::is_nothrow_move_assignable_v && std::is_nothrow_assignable_v) - { - where_ = std::move(where); - which_ = std::forward(which); - } - - [[nodiscard]] constexpr explicit operator bool() const noexcept { return !which_.empty(); } - [[nodiscard]] constexpr bool has_value() const noexcept { return !which_.empty(); } - - constexpr void swap(expectation_failure& other) - noexcept(std::is_nothrow_swappable_v && std::is_nothrow_swappable_v) - { - using std::swap; - swap(where_, other.where_); - swap(which_, other.which_); - } - -private: - It where_{}; - std::string which_; -}; - -template -constexpr void swap(expectation_failure& a, expectation_failure& b) - noexcept(std::is_nothrow_swappable_v && std::is_nothrow_swappable_v) -{ - a.swap(b); -} - template using expectation_failure_t = get_context_plain_t; diff --git a/include/iris/x4/core/expectation_failure.hpp b/include/iris/x4/core/expectation_failure.hpp new file mode 100644 index 000000000..ad7e6d8a2 --- /dev/null +++ b/include/iris/x4/core/expectation_failure.hpp @@ -0,0 +1,97 @@ +#ifndef IRIS_ZZ_X4_CORE_EXPECTATION_FAILURE_HPP +#define IRIS_ZZ_X4_CORE_EXPECTATION_FAILURE_HPP + +/*============================================================================= + Copyright (c) 2017 wanghan02 + Copyright (c) 2024-2025 Nana Sakisaka + Copyright (c) 2026 The Iris Project Contributors + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ + +// This header is intended for inclusion by user-facing, non-parser headers. +// Do not add includes specific to X4's parser implementation here. + +#include + +#include +#include +#include +#include + +#include + +namespace iris::x4 { + +template +struct expectation_failure +{ + constexpr expectation_failure() = default; + + template + requires std::is_constructible_v + constexpr expectation_failure(It where, WhichT&& which) + noexcept(std::is_nothrow_copy_constructible_v && std::is_nothrow_constructible_v) + : where_(where) + , which_(std::forward(which)) + { + if (which_.empty()) { + which_ = "(unknown location)"; + } + } + + [[nodiscard]] + constexpr It const& where() const noexcept + { + assert(this->has_value()); + return where_; + } + + [[nodiscard]] + constexpr std::string const& which() const noexcept + { + assert(this->has_value()); + return which_; + } + + constexpr void clear() noexcept + { + which_.clear(); + } + + template + requires std::is_constructible_v + constexpr void emplace(It where, WhichT&& which) + noexcept(std::is_nothrow_move_assignable_v && std::is_nothrow_assignable_v) + { + where_ = std::move(where); + which_ = std::forward(which); + } + + [[nodiscard]] constexpr explicit operator bool() const noexcept { return !which_.empty(); } + [[nodiscard]] constexpr bool has_value() const noexcept { return !which_.empty(); } + + constexpr void swap(expectation_failure& other) + noexcept(std::is_nothrow_swappable_v && std::is_nothrow_swappable_v) + { + using std::swap; + swap(where_, other.where_); + swap(which_, other.which_); + } + +private: + It where_{}; + std::string which_; +}; + +template +constexpr void swap(expectation_failure& a, expectation_failure& b) + noexcept(std::is_nothrow_swappable_v && std::is_nothrow_swappable_v) +{ + a.swap(b); +} + +} // iris::x4 + +#endif diff --git a/include/iris/x4/parse_result.hpp b/include/iris/x4/parse_result.hpp index 8feb694cc..1409b3da1 100644 --- a/include/iris/x4/parse_result.hpp +++ b/include/iris/x4/parse_result.hpp @@ -9,8 +9,11 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ +// This header is intended for inclusion by user-facing, non-parser headers. +// Do not add includes specific to X4's parser implementation here. + #include -#include +#include #include #include