Код: Выделить всё
#include
#include
#include
#include
template
consteval auto index_of_type() -> uint64_t
{
uint64_t idx = 0;
// CANNOT BE CONSTEXPR EVEN THOUGH IT IS CONSTEXPR
// REMOVING constexpr MAKES IT COMPILE. AND THIS FUNCTION IS CONSTEVAL
constexpr bool bFound = ((++idx, std::is_same_v) || ...);
return idx - 1;
}
template
consteval auto index_of_tyoe_in_tuple(const std::tuple&) -> uint64_t
{
return index_of_type();
}
int main(int argc, char* argv[])
{
constexpr std::tuple my_tuple;
constexpr int idx = index_of_tyoe_in_tuple(my_tuple);
}
Я не могу сделать static_assert (bfound) Если я не сделаю bfound contexpr. Таким образом, в нем говорится, что IDX> 20 не является constexPR, и все же возврат IDX - 1 на самом деле постоянно. Странно.
Подробнее здесь: https://stackoverflow.com/questions/796 ... -compile-t
Мобильная версия