Hello,
I’m writing a variadic template function like:
template <typename... PayloadTypes>
RT_DEVICE_FUNCTION void getPayloads(PayloadTypes*... payloads) {
constexpr size_t numDwords = detail::calcSumDwords<PayloadTypes...>();
...
}
, where detail::calcSumDwords<>()
is a function to get the total size of template parameters.
template <typename HeadType, typename... TailTypes>
RT_DEVICE_FUNCTION constexpr size_t _calcSumDwords() {
uint32_t ret = sizeof(HeadType) / sizeof(uint32_t);
if constexpr (sizeof...(TailTypes) > 0)
ret += _calcSumDwords<TailTypes...>();
return ret;
}
template <typename... PayloadTypes>
RT_DEVICE_FUNCTION constexpr size_t calcSumDwords() {
if constexpr (sizeof...(PayloadTypes) > 0)
return _calcSumDwords<PayloadTypes...>();
else
return 0;
}
The programming guide says the latest nvcc supports C++17 features:
All C++17 language features are supported in nvcc version 11.0 and later, subject to restrictions described here.
I thought that calcDwords()
can be replaced by simpler fold expression in C++17 like
constexpr size_t numDwords = (sizeof(PayloadTypes) + ...);
but got errors:
error : expected an expression
parameter pack “PayloadTypes” was referenced but not expanded
Does nvcc supports fold expression in C++17?
Thanks