This is a long shot, however I'm trying to infer a universal reference of type std::list<T>
for some T
.
I have something like this:
// Is the type A the same as B, regardless of const and references
template <typename A, typename B>
struct is_same_kind {
static constexpr auto value = std::is_same_v<std::remove_cv_t<std::remove_reference_t<A>>,
std::remove_cv_t<std::remove_reference_t<B>>>;
};
template <typename A, typename B>
static constexpr auto is_same_kind_v = is_same_kind<A,B>::value;
template<typename L, typename T, typename = std::enable_if_t<is_same_kind_v<L, std::list<T>>>>
T head(L&& l) {
return *std::forward<L>(l).begin();
}
I get an error as the preprocessor is not able to infer T
. Maybe there's some nice trick to infer both L&&
as universal reference to std::list<T>
and the type T
from the argument l
?
EDIT: Here's how to call it for example:
int main() {
std::cout << head(std::list{1,2,3});
}
I expect to get 1.