Once again, @kerrek-sb explains how to correctly use std:decay
when implementing perfect forwarding (both in C++11 and C++14)
Here's the answer.
I found myself in a similar situation. Namely, I was trying to implement a generic algorithm via tag dispatching.
namespace detail {
template<class Range>
void implementation(Range&& range, std::true_type is_sorted);
template<class Range>
void implementation(Range&& range, std::false_type is_not_sorted);
}
Assuming the existence of a is_range_sorted
metafunction, implementation
should read as follows:
template<class Range>
void implementation(Range&& range) {
usign range_type = typename std::decay<Range>::type;
return detail::implementation(std::forward<Range>(range),
typename is_range_sorted<range_type>::type());
}
This is similar to how std::decay
is used when implement std::make_pair
, see here.