99#ifndef ORC_RT_ERROR_H
1010#define ORC_RT_ERROR_H
1111
12+ #include " orc-rt/CallableTraitsHelper.h"
1213#include " orc-rt/Compiler.h"
1314#include " orc-rt/RTTI.h"
1415
@@ -137,31 +138,27 @@ template <typename ErrT, typename... ArgTs> Error make_error(ArgTs &&...Args) {
137138 return make_error (std::make_unique<ErrT>(std::forward<ArgTs>(Args)...));
138139}
139140
140- // / Traits class for selecting and applying error handlers.
141- template <typename HandlerT>
142- struct ErrorHandlerTraits
143- : public ErrorHandlerTraits<
144- decltype (&std::remove_reference_t <HandlerT>::operator ())> {};
141+ namespace detail {
142+
143+ template <typename RetT, typename ArgT> struct ErrorHandlerTraitsImpl ;
145144
146- // Specialization functions of the form ' Error (const ErrT&)' .
147- template <typename ErrT> struct ErrorHandlerTraits <Error (&)( ErrT &) > {
145+ // Specialization for Error( ErrT&).
146+ template <typename ErrT> struct ErrorHandlerTraitsImpl <Error, ErrT &> {
148147 static bool appliesTo (const ErrorInfoBase &E) {
149148 return E.template isA <ErrT>();
150149 }
151-
152150 template <typename HandlerT>
153151 static Error apply (HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) {
154152 assert (appliesTo (*E) && " Applying incorrect handler" );
155153 return H (static_cast <ErrT &>(*E));
156154 }
157155};
158156
159- // Specialization functions of the form ' void (const ErrT&)' .
160- template <typename ErrT> struct ErrorHandlerTraits <void (&)( ErrT &) > {
157+ // Specialization for void( ErrT&).
158+ template <typename ErrT> struct ErrorHandlerTraitsImpl <void , ErrT &> {
161159 static bool appliesTo (const ErrorInfoBase &E) {
162160 return E.template isA <ErrT>();
163161 }
164-
165162 template <typename HandlerT>
166163 static Error apply (HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) {
167164 assert (appliesTo (*E) && " Applying incorrect handler" );
@@ -170,13 +167,12 @@ template <typename ErrT> struct ErrorHandlerTraits<void (&)(ErrT &)> {
170167 }
171168};
172169
173- // / Specialization for functions of the form ' Error (std::unique_ptr<ErrT>)' .
170+ // Specialization for Error(std::unique_ptr<ErrT>).
174171template <typename ErrT>
175- struct ErrorHandlerTraits <Error (&)( std::unique_ptr<ErrT>) > {
172+ struct ErrorHandlerTraitsImpl <Error, std::unique_ptr<ErrT>> {
176173 static bool appliesTo (const ErrorInfoBase &E) {
177174 return E.template isA <ErrT>();
178175 }
179-
180176 template <typename HandlerT>
181177 static Error apply (HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) {
182178 assert (appliesTo (*E) && " Applying incorrect handler" );
@@ -185,13 +181,12 @@ struct ErrorHandlerTraits<Error (&)(std::unique_ptr<ErrT>)> {
185181 }
186182};
187183
188- // / Specialization for functions of the form ' void (std::unique_ptr<ErrT>)' .
184+ // Specialization for void(std::unique_ptr<ErrT>).
189185template <typename ErrT>
190- struct ErrorHandlerTraits <void (&)( std::unique_ptr<ErrT>) > {
186+ struct ErrorHandlerTraitsImpl <void , std::unique_ptr<ErrT>> {
191187 static bool appliesTo (const ErrorInfoBase &E) {
192188 return E.template isA <ErrT>();
193189 }
194-
195190 template <typename HandlerT>
196191 static Error apply (HandlerT &&H, std::unique_ptr<ErrorInfoBase> E) {
197192 assert (appliesTo (*E) && " Applying incorrect handler" );
@@ -201,37 +196,11 @@ struct ErrorHandlerTraits<void (&)(std::unique_ptr<ErrT>)> {
201196 }
202197};
203198
204- // Specialization for member functions of the form 'RetT (const ErrT&)'.
205- template <typename C, typename RetT, typename ErrT>
206- class ErrorHandlerTraits <RetT (C::*)(ErrT &)>
207- : public ErrorHandlerTraits<RetT (&)(ErrT &)> {};
208-
209- // Specialization for member functions of the form 'RetT (const ErrT&) const'.
210- template <typename C, typename RetT, typename ErrT>
211- class ErrorHandlerTraits <RetT (C::*)(ErrT &) const >
212- : public ErrorHandlerTraits<RetT (&)(ErrT &)> {};
213-
214- // Specialization for member functions of the form 'RetT (const ErrT&)'.
215- template <typename C, typename RetT, typename ErrT>
216- class ErrorHandlerTraits <RetT (C::*)(const ErrT &)>
217- : public ErrorHandlerTraits<RetT (&)(ErrT &)> {};
218-
219- // Specialization for member functions of the form 'RetT (const ErrT&) const'.
220- template <typename C, typename RetT, typename ErrT>
221- class ErrorHandlerTraits <RetT (C::*)(const ErrT &) const >
222- : public ErrorHandlerTraits<RetT (&)(ErrT &)> {};
223-
224- // / Specialization for member functions of the form
225- // / 'RetT (std::unique_ptr<ErrT>)'.
226- template <typename C, typename RetT, typename ErrT>
227- class ErrorHandlerTraits <RetT (C::*)(std::unique_ptr<ErrT>)>
228- : public ErrorHandlerTraits<RetT (&)(std::unique_ptr<ErrT>)> {};
229-
230- // / Specialization for member functions of the form
231- // / 'RetT (std::unique_ptr<ErrT>) const'.
232- template <typename C, typename RetT, typename ErrT>
233- class ErrorHandlerTraits <RetT (C::*)(std::unique_ptr<ErrT>) const >
234- : public ErrorHandlerTraits<RetT (&)(std::unique_ptr<ErrT>)> {};
199+ } // namespace detail.
200+
201+ template <typename C>
202+ struct ErrorHandlerTraits
203+ : public CallableTraitsHelper<detail::ErrorHandlerTraitsImpl, C> {};
235204
236205inline Error handleErrorsImpl (std::unique_ptr<ErrorInfoBase> Payload) {
237206 return make_error (std::move (Payload));
0 commit comments