C++ Logo

std-discussion

Advanced search

Re: a trait for contextual convertible to bool?

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 18 Jan 2021 11:33:01 +0200
On Mon, 18 Jan 2021 at 11:26, Peter Sommerlad (C++) via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Hi
>
> while trying to implement a better Bool than bool (no implicit
> artithmetic, no implicit conversion from arithmetic types) I figured
> that there is no trait that models contextual convertibility to bool,
> i.e., std::istream& is contextual convertible to bool, but
> std::is_convertible<std::istream&,bool> is false_type as well as
> std::convertible_to<std::istream&,bool> fails.
>
> Do other feel the need to have such a trait modelling contextual
> conversion to bool, or is there a trait that would allow that?
>
> I implemented my own that provides explicit conversion to bool from
> class types and pointers, which is what I want to support for my Bool type.

Why would I need such a trait? Is it something more than
constructible_from<bool, T>?

Received on 2021-01-18 03:33:15