On Tue, Jun 28, 2016 at 11:33 PM, <
left...@gmail.com> wrote:
>
>
> Succeeds to compile.
>
> It would be my opinion that the if-constexpr conditional *should*
> short-circuit at compile time, but I don't see if the accepted proposal
> specifies one way or the other.
It compiles not because of short-circuit but sfinae in
general; it still works if you swap the sub-expressions
around &&. If that is the behavior you expect we
need to say that substitution failures give false values.
However, I'm skeptical about its generality.
The constexpr if example you gave is truly equiv to
the following:
#include <type_traits>
struct MyType
{
static const int i = 5;
};
template<typename T>
auto do_thing(const T &t, std::true_type)
{
}
template<typename T>
auto do_thing(const T &t, std::false_type)
{
}
template<typename T>
auto do_thing(const T &t)
{
return do_thing(t, std::bool_constant<std::is_same_v<MyType, T> &&
T::i == 5>());
}
int main()
{
do_thing(MyType());
do_thing(3);
}
, which doesn't work in the same way.
OK, Jens answered it... And it's way better than
what I'm going to suggest, which is based on
constexpr lambda expression sfinae...
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD --
http://blog.miator.net/