I am reading a book, that explains C++ traits and there is an example from C++ type_traits header with a strange
template<typename _Tp, typename _Up>
static __success_type<typename decay<decltype
(true ? std::declval<_Tp>()
: std::declval<_Up>())>::type> _S_test(int);
In the expression
true ? std::declval<_Tp>() : std::declval<_Up>() the first alternative is always selected, but the whole expression must be a valid expression. So
std::declval<_Up>() must be valid and that means
_Up must be a callable that accepts zero arguments. Beside that,
_Up() must return the same type (or one of the types must be implicitly convertible to another), otherwise ternary iterator would not be able to select return value.
This technique is called SFINAE. The idea is that if template instantiation fails, then it is not an error, and this template is just ignored and compiler searches for another one.