Use enable_if to control what types can instantiate a template
Using a `static_assert(false, ...)` expression in the `else` block of a `if constexpr` statement doesn't work. The `else` block is not protected by the `constexpr`-ness of the `if`s, so it is always compiled. Consequently it will always fail to compile. Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
+6
-5
@@ -6,6 +6,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/std/typetraits/disjunction.h>
|
||||
#include <TestImpactFramework/TestImpactClientSequenceReportSerializer.h>
|
||||
#include <TestImpactFramework/TestImpactSequenceReportException.h>
|
||||
#include <TestImpactFramework/TestImpactUtils.h>
|
||||
@@ -735,7 +736,11 @@ namespace TestImpact
|
||||
};
|
||||
}
|
||||
|
||||
template<typename PolicyStateType>
|
||||
template<typename PolicyStateType, typename = AZStd::enable_if_t<AZStd::disjunction_v<
|
||||
AZStd::is_same<PolicyStateType, SequencePolicyState>,
|
||||
AZStd::is_same<PolicyStateType, SafeImpactAnalysisSequencePolicyState>,
|
||||
AZStd::is_same<PolicyStateType, ImpactAnalysisSequencePolicyState>
|
||||
>>>
|
||||
PolicyStateType DeserializePolicyStateType(const rapidjson::Value& serialPolicyStateType)
|
||||
{
|
||||
if constexpr (AZStd::is_same_v<PolicyStateType, SequencePolicyState>)
|
||||
@@ -750,10 +755,6 @@ namespace TestImpact
|
||||
{
|
||||
return DeserializeImpactAnalysisSequencePolicyStateMembers(serialPolicyStateType);
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(false, "Template paramater must be a valid policy state type");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename SequenceReportBaseType>
|
||||
|
||||
Reference in New Issue
Block a user