diff --git a/pxr/base/vt/types.h b/pxr/base/vt/types.h index 46ab190154..13d0c41dd9 100644 --- a/pxr/base/vt/types.h +++ b/pxr/base/vt/types.h @@ -33,11 +33,11 @@ #include "pxr/base/arch/inttypes.h" #include "pxr/base/gf/declare.h" #include "pxr/base/gf/half.h" +#include "pxr/base/tf/meta.h" #include "pxr/base/tf/preprocessorUtilsLite.h" #include "pxr/base/tf/token.h" #include -#include #include #include @@ -189,33 +189,54 @@ VT_ARRAY_VALUE_TYPES VT_SCALAR_CLASS_VALUE_TYPES VT_NONARRAY_VALUE_TYPES #define VT_VALUE_TYPES \ VT_BUILTIN_VALUE_TYPES VT_CLASS_VALUE_TYPES +#define _VT_MAP_TYPE_LIST(r, unused, elem) , VT_TYPE(elem) + +// Populate a type list from the preprocessor sequence. +// void is prepended to match the comma for the first type +// and then dropped by TfMetaTail. +using Vt_ValueTypeList = + TfMetaApply>; + namespace Vt_KnownValueTypeDetail { // Implement compile-time value type indexes. -// // Base case -- unknown types get index -1. -template +template constexpr int -GetIndex() { +GetIndexImpl(TfMetaList<>) { return -1; } -// Set indexes for known types. -#define VT_SET_VALUE_TYPE_INDEX(r, unused, i, elem) \ - template <> constexpr int \ - GetIndex< VT_TYPE(elem) >() { \ - return i; \ +template +constexpr int +GetIndexImpl(Typelist) { + if (std::is_same_v>) { + return 0; + } + else if (const int indexOfTail = + GetIndexImpl(TfMetaApply{}); + indexOfTail >= 0) { + return 1 + indexOfTail; } -BOOST_PP_SEQ_FOR_EACH_I(VT_SET_VALUE_TYPE_INDEX, ~, VT_VALUE_TYPES) -#undef VT_SET_VALUE_TYPE_INDEX + else { + return -1; + } +} + +template +constexpr int +GetIndex() { + return GetIndexImpl(Vt_ValueTypeList{}); +} } // Vt_KnownValueTypeDetail // Total number of 'known' value types. constexpr int VtGetNumKnownValueTypes() { - return BOOST_PP_SEQ_SIZE(VT_VALUE_TYPES); + return TfMetaApply::value; } /// Provide compile-time value type indexes for types that are "known" to Vt -- diff --git a/pxr/base/vt/visitValue.h b/pxr/base/vt/visitValue.h index 65cc2a68ae..f1c83883a4 100644 --- a/pxr/base/vt/visitValue.h +++ b/pxr/base/vt/visitValue.h @@ -109,12 +109,12 @@ auto VtVisitValue(VtValue const &value, Visitor &&visitor) switch (value.GetKnownValueTypeIndex()) { // Cases for known types. -#define VT_CASE_FOR_TYPE_INDEX(r, unused, i, elem) \ - case i: \ +#define VT_CASE_FOR_TYPE_INDEX(r, unused, elem) \ + case VtGetKnownValueTypeIndex(): \ return Vt_ValueVisitDetail::Visit( \ value, std::forward(visitor), 0); \ break; -BOOST_PP_SEQ_FOR_EACH_I(VT_CASE_FOR_TYPE_INDEX, ~, VT_VALUE_TYPES) +BOOST_PP_SEQ_FOR_EACH(VT_CASE_FOR_TYPE_INDEX, ~, VT_VALUE_TYPES) #undef VT_CASE_FOR_TYPE_INDEX default: