diff --git a/include/onnxruntime/core/framework/data_types_internal.h b/include/onnxruntime/core/framework/data_types_internal.h index 7dfd5da467..23e4166e20 100644 --- a/include/onnxruntime/core/framework/data_types_internal.h +++ b/include/onnxruntime/core/framework/data_types_internal.h @@ -224,10 +224,11 @@ inline bool IsPrimitiveDataType(const PrimitiveDataTypeBase* prim_type) { // GCC until very recently does not support template parameter pack expansion within lambda context. namespace mltype_dispatcher_internal { // T - type handled by this helper -struct CallableDispatchableHelper { +class CallableDispatchableHelper { int32_t dt_type_; // Type currently dispatched size_t called_; + public: explicit CallableDispatchableHelper(int32_t dt_type) noexcept : dt_type_(dt_type), called_(0) {} // Must return integer to be in a expandable context @@ -239,6 +240,11 @@ struct CallableDispatchableHelper { } return 0; } + + void CheckCalledOnce() { + ORT_ENFORCE(called_ < 2, "Check for duplicate types in MLTypeCallDispatcher"); + ORT_ENFORCE(called_ == 1, "Unsupported data type: ", dt_type_); + } }; // Default policy is to throw with no return type. @@ -251,11 +257,12 @@ struct UnsupportedTypeDefaultPolicy { // Helper with the result type template > -struct CallableDispatchableRetHelper { +class CallableDispatchableRetHelper { int32_t dt_type_; // Type currently dispatched size_t called_; Ret result_; + public: explicit CallableDispatchableRetHelper(int32_t dt_type) noexcept : dt_type_(dt_type), called_(0), result_() {} Ret Get() { @@ -312,8 +319,7 @@ class MLTypeCallDispatcher { mltype_dispatcher_internal::CallableDispatchableHelper helper(dt_type_); int results[] = {0, helper.template Invoke(Fn(), std::forward(args)...)...}; ORT_UNUSED_PARAMETER(results); - ORT_ENFORCE(helper.called_ < 2, "Check for duplicate types in MLTypeCallDispatcher"); - ORT_ENFORCE(helper.called_ == 1, "Unsupported data type: ", dt_type_); + helper.CheckCalledOnce(); } }; @@ -370,7 +376,7 @@ class MLTypeCallDispatcher2 { // avoid "unused parameter" warning for the case where Types is empty static_cast(std::array{(ORT_UNUSED_PARAMETER(args), 0)...}); - ORT_ENFORCE(helper.called_ == 1, "Unsupported data type: ", dt_type_); + helper.CheckCalledOnce(); } template