Language
Compiler
Options
#include <utility>
template<size_t I> struct priority_tag : priority_tag<I-1> {};
template<> struct priority_tag<0> {};
namespace CNL_customization {
template<class T> struct do_halve;
}
namespace CNL_detail {
template<class T>
auto detail_halve(T t, priority_tag<0>) -> decltype(t / 2)
{
// lower priority (priority 0)
return t / 2;
}
template<class T>
auto detail_halve(T t, priority_tag<1>) -> decltype(do_halve(t))
{
// higher priority (priority 1)
return do_halve(t);
}
template<class T>
auto detail_halve(T t, priority_tag<2>) -> decltype(CNL_customization::do_halve<T>::_(t))
{
// highest priority (priority 2)
return CNL_customization::do_halve<T>::_(t);
}
}
namespace CNL {
inline constexpr auto cpo_halve = [](auto&& t)
-> decltype(CNL_detail::detail_halve(std::forward<decltype(t)>(t), priority_tag<2>{}))
{
return CNL_detail::detail_halve(std::forward<decltype(t)>(t), priority_tag<2>{});
$
Exit Code:
0