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:
Chris Burel
2022-02-10 15:23:48 -08:00
parent 20e268930c
commit 86aa5093ec
@@ -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>