I am reading a book that explains the features of C ++, and there is an example from the C ++ header of type_traits with strange usage ?: , Here is a quote from the corresponding file / usr / include / C ++ / ...:
template<typename _Tp, typename _Up> static __success_type<typename decay<decltype (true ? std::declval<_Tp>() : std::declval<_Up>())>::type> _S_test(int);
Overriding the purpose of this declaration, the use of the ?: Operator causes puzzles in this case. If the first operand is true , then std::declval<_Tp>() will always be selected as a result of the evaluation. How does this descriptive operand selection work?
Edit: originally read in Nicolae M. Josuttis "C ++ Standard Library: Tutorial and Reference, 2nd ed.", P. 125. But there it is given in a slightly simplified form compared to my GCC header files.
source share