File indexing completed on 2026-08-17 08:52:03
0001
0002
0003
0004
0005
0006 #ifndef BOOST_OPENMETHOD_POLICY_VECTORED_ERROR_HPP
0007 #define BOOST_OPENMETHOD_POLICY_VECTORED_ERROR_HPP
0008
0009 #include <boost/openmethod/preamble.hpp>
0010
0011 #include <functional>
0012 #include <variant>
0013
0014 namespace boost::openmethod::policies {
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 struct default_error_handler : error_handler {
0035
0036
0037
0038 template<class Registry>
0039 class fn {
0040 template<typename, typename, typename>
0041 struct error_variant_aux;
0042
0043 template<
0044 typename T, class... Errors, class Policy, class... MorePolicies>
0045 struct error_variant_aux<
0046 T, std::variant<Errors...>, mp11::mp_list<Policy, MorePolicies...>>
0047 : error_variant_aux<
0048 void, std::variant<Errors...>,
0049 mp11::mp_list<MorePolicies...>> {};
0050
0051 template<class... Errors, class Policy, class... MorePolicies>
0052 struct error_variant_aux<
0053 std::void_t<typename Policy::errors>, std::variant<Errors...>,
0054 mp11::mp_list<Policy, MorePolicies...>>
0055 : error_variant_aux<
0056 void,
0057 mp11::mp_append<
0058 std::variant<Errors...>, typename Policy::errors>,
0059 mp11::mp_list<MorePolicies...>> {};
0060
0061 template<class... Errors>
0062 struct error_variant_aux<
0063 void, std::variant<Errors...>, mp11::mp_list<>> {
0064 using type = std::variant<Errors...>;
0065 };
0066
0067 public:
0068
0069
0070 using error_variant = typename error_variant_aux<
0071 void,
0072 std::variant<
0073 not_initialized, no_overrider, ambiguous_call, missing_class,
0074 missing_base, odr_violation, final_error>,
0075 typename Registry::policy_list>::type;
0076
0077
0078 using function_type = std::function<void(const error_variant& error)>;
0079
0080
0081
0082
0083
0084
0085 template<class Error>
0086 static auto error(const Error& error) -> void {
0087 handler(error_variant(error));
0088 }
0089
0090
0091
0092
0093
0094
0095
0096
0097 static auto set(function_type new_handler) -> function_type {
0098 auto prev = handler;
0099 handler = std::move(new_handler);
0100
0101 return prev;
0102 }
0103
0104
0105
0106
0107
0108
0109
0110 static auto default_handler(const error_variant& error) -> void {
0111 if constexpr (Registry::has_output) {
0112 std::visit(
0113 [](auto&& error) {
0114 error.template write<Registry>(Registry::output::os);
0115 },
0116 error);
0117 Registry::output::os << "\n";
0118 }
0119 }
0120
0121 private:
0122 static function_type handler;
0123 };
0124 };
0125
0126 template<class Registry>
0127 typename default_error_handler::fn<Registry>::function_type
0128 default_error_handler::fn<Registry>::handler = default_handler;
0129
0130 }
0131
0132 #endif