diff --git a/include/chaiscript/dispatchkit/exception_specification.hpp b/include/chaiscript/dispatchkit/exception_specification.hpp index 1b4384b..0c9b40f 100644 --- a/include/chaiscript/dispatchkit/exception_specification.hpp +++ b/include/chaiscript/dispatchkit/exception_specification.hpp @@ -23,12 +23,11 @@ namespace chaiscript { namespace detail { - /// \todo make this a variadic template struct Exception_Handler_Base { virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0; - virtual ~Exception_Handler_Base() {} + virtual ~Exception_Handler_Base() = default; protected: template @@ -38,65 +37,12 @@ namespace chaiscript } }; - template - struct Exception_Handler_Impl1 : Exception_Handler_Base + template + struct Exception_Handler_Impl : Exception_Handler_Base { - virtual ~Exception_Handler_Impl1() {} - - virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override + void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override { - throw_type(bv, t_engine); - } - }; - template - struct Exception_Handler_Impl2 : Exception_Handler_Base - { - virtual ~Exception_Handler_Impl2() {} - - virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override - { - throw_type(bv, t_engine); - throw_type(bv, t_engine); - } - }; - - template - struct Exception_Handler_Impl3 : Exception_Handler_Base - { - virtual ~Exception_Handler_Impl3() {} - - virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override - { - throw_type(bv, t_engine); - throw_type(bv, t_engine); - throw_type(bv, t_engine); - } - }; - template - struct Exception_Handler_Impl4 : Exception_Handler_Base - { - virtual ~Exception_Handler_Impl4() {} - - virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override - { - throw_type(bv, t_engine); - throw_type(bv, t_engine); - throw_type(bv, t_engine); - throw_type(bv, t_engine); - } - }; - template - struct Exception_Handler_Impl5 : Exception_Handler_Base - { - virtual ~Exception_Handler_Impl5() {} - - virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override - { - throw_type(bv, t_engine); - throw_type(bv, t_engine); - throw_type(bv, t_engine); - throw_type(bv, t_engine); - throw_type(bv, t_engine); + (void)std::initializer_list{(throw_type(bv, t_engine), 0)...}; } }; } @@ -155,42 +101,10 @@ namespace chaiscript /// \brief creates a chaiscript::Exception_Handler which handles one type of exception unboxing /// \sa \ref exceptions - template + template Exception_Handler exception_specification() { - return Exception_Handler(new detail::Exception_Handler_Impl1()); - } - - /// \brief creates a chaiscript::Exception_Handler which handles two types of exception unboxing - /// \sa \ref exceptions - template - Exception_Handler exception_specification() - { - return Exception_Handler(new detail::Exception_Handler_Impl2()); - } - - /// \brief creates a chaiscript::Exception_Handler which handles three types of exception unboxing - /// \sa \ref exceptions - template - Exception_Handler exception_specification() - { - return Exception_Handler(new detail::Exception_Handler_Impl3()); - } - - /// \brief creates a chaiscript::Exception_Handler which handles four types of exception unboxing - /// \sa \ref exceptions - template - Exception_Handler exception_specification() - { - return Exception_Handler(new detail::Exception_Handler_Impl4()); - } - - /// \brief creates a chaiscript::Exception_Handler which handles five types of exception unboxing - /// \sa \ref exceptions - template - Exception_Handler exception_specification() - { - return Exception_Handler(new detail::Exception_Handler_Impl5()); + return std::make_shared>(); } }