Reference:
https://en.cppreference.com/w/cpp/language/pack_indexinghttps://godbolt.org/z/9eP8qT64s
#include <type_traits>
template <typename... Ts>
using last_type_t = Ts...[sizeof...(Ts) - 1];
template<typename... T>
void run(T... t) {
decltype(t...[1]) i = 0; // float
}
int main() {
static_assert(std::is_same_v<last_type_t<int>, int>);
static_assert(std::is_same_v<last_type_t<bool, char>, char>);
static_assert(std::is_same_v<last_type_t<float, int, bool*>, bool*>);
struct tmp{};
run(1, 2.0f, tmp{});
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.