[Bug c++/86282] Evaluation order in if constexpr expression seems to be irrelevant for evaluating type traits
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jun 22 14:10:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86282
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Using std::conjunction:
template<typename T>
using has_begin2 = std::bool_constant<has_begin<T>>;
template<typename T>
struct has_nested_begin
{
// ill-formed unless has_begin<T> is true:
static constexpr bool value =
has_begin<std::remove_reference_t<decltype(*std::begin(std::declval<T>()))>>;
};
template<typename T>
int f(T)
{
if (std::conjunction_v<has_begin2<T>, has_nested_begin<T>>)
return 0;
return 1;
}
When has_begin2<T>::value is false, has_nested_begin<T>::value is not needed,
so is not instantiated.
More information about the Gcc-bugs
mailing list