[libcxx-commits] [PATCH] D58019: Add is_nothrow_convertible (P0758R1)

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 12 10:46:57 PST 2019


ldionne added a comment.

In D58019#1395157 <https://reviews.llvm.org/D58019#1395157>, @zoecarver wrote:

> @ldionne just for reference, this is what it would look like to use `is_nothrow_constructible`:
>
>    template <typename _Fm, typename _To>
>    struct is_nothrow_convertible : __and_<
>        is_convertible<_Fm, _To>,
>        __libcpp_is_nothrow_constructible<true, true, _Fm, _To>
>   >::type { };
>   


Right -- I'd rather we reimplement the checking ourselves instead of relying on `__libcpp_is_nothrow_constructible<true, true, _Fm, _To>` (where we'd be lying about the reference-ness of `_To`.



================
Comment at: include/type_traits:1558
+    __or_<
+        is_void<_Fm>, is_function<_To>, is_array<_To>
+    >::value
----------------
zoecarver wrote:
> zoecarver wrote:
> > ldionne wrote:
> > > I don't think this is useful anymore, as this should be handled by `std::is_convertible`. IOW, I think only the test for `noexcept`-ness of the conversion needs to exist, not for convertibility.
> > Good catch, you're completely right. In fact, we could probably simplify this a lot and just have it use `is_nothrow_constructible<_Fm, _To>`. I am a bit hesitant to do that because it isn't what `is_nothrow_constructible`'s intended use is, what do you think?
> Actually correction: `void` will not work in the below `__test_noexcept` method so it has to have its own overload. But I can get rid of the `is_array`/`is_function` checks (because those will be caught by `std::is_convertible`).
Makes sense, see my suggestion below. I don't think we can use `is_nothrow_constructible`, since the check for non-reference types is:
```
integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
```

That's not checking whether the conversion operator is `noexcept`, only a constructor.



================
Comment at: include/type_traits:1586
+template <typename _Fm, typename _To>
+struct is_nothrow_convertible : __and_<is_convertible<_Fm, _To>,
+    __is_nothrow_convertible_helper<_Fm, _To>>::type
----------------
How about this:

```
__or<
  __and_<is_void<_Fm>, is_void<_To>>,
  __and<is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
>
```

And then `__is_nothrow_convertible_helper` doesn't have to care about `void`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58019/new/

https://reviews.llvm.org/D58019





More information about the libcxx-commits mailing list