[libcxx-commits] [PATCH] D58019: Add is_nothrow_convertible (P0758R1)
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 11 09:35:29 PST 2019
ldionne added a comment.
Actually, I'm looking at this and `std::is_convertible` again, and I think this should be using `std::is_convertible` in the implementation. I know the paper suggests the implementation in this patch, however it's unclear to me whether that implementation properly handles all the cases that `std::is_convertible` handles (notably with references). Also, using `std::is_convertible` under the hood means that we will use the `__is_convertible_to` intrinsic when it's available instead.
I would do something like this instead (untested):
template <typename _Fm, typename _To>
struct __is_nothrow_convertible_impl {
private:
template <typename _Tp>
static void __test_noexcept(_Tp) noexcept;
template<typename __Fm, typename __To>
static bool_constant<noexcept(__test_noexcept<__To>(declval<__Fm>()))>
__test(int);
template<typename, typename>
static false_type
__test(...);
public:
using type = decltype(__test<_Fm, _To>(0));
};
template <typename _Fm, typename _To>
struct is_nothrow_convertible : __and_<is_convertible<_Fm, _To>, __is_nothrow_convertible_impl<_Fm, _To>>
{ };
This is very similar to what you have, but I also guard the whole thing with `std::is_convertible`. What do you think? Did I miss a subtlety that would make my draft implementation wrong (that's quite possible)?
Repository:
rCXX libc++
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58019/new/
https://reviews.llvm.org/D58019
More information about the libcxx-commits
mailing list