[PATCH] D44865: [libc++] Implement P0608R1 - A sane variant converting constructor

Zhihao Yuan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 26 20:30:44 PDT 2018


lichray marked an inline comment as done.
lichray added a comment.

In https://reviews.llvm.org/D44865#1048880, @EricWF wrote:

> Has this paper been adopted into the standard yet?


No.  However, it cleanly passed LEWG for recommending a DR against C++17, so I think we can apply it early, just like we sometimes make changes before filing issues :)



================
Comment at: include/variant:1109
 
+#define _LIBCPP_VARIANT_BOOLEAN_CONVERSION(bool_type)                    \
+    template <class... _Types>                                           \
----------------
EricWF wrote:
> EricWF wrote:
> > I would like to see a version of this patch that doesn't use preprocessor expansion to specialize `__overload` multiple times.
> > 
> > Perhaps adding a `bool = is_same<remove_cv_t<First>, bool>` to `__overload` and then specializing once on that?
> Or perhaps SFINAE-ing the `test` member instead of specializing `__overload`.
> 
> Something like this maybe?
> 
> ```
> 
> template <class _Tp, class... _Types>
> struct __overload< _Tp, _Types...> : __overload<_Types...>
> {
>     using __overload<_Types...>::operator();
> 
>     template <bool _EnableBool>
>     using _DepIsBool = typename __dependent_type<
>         enable_if<is_same_v<remove_cv_t<_Tp>, bool> == _EnableBool>, _EnableBool
>     >::type;
> 
>     template <class _Up, bool _EnableBool = false, class = _DepIsBool<_EnableBool>>
>     auto operator()(_Tp, _Up&& __t) const
>       -> decltype(_Tp{__t}, __identity<_Tp>());
> 
>     template <class _Up, class _Ap = __uncvref_t<_Up>,
>         bool _EnableIfBool = true, class = _DepIsBool<_EnableIfBool>>
>     auto operator()(bool, _Up&&, int _Ap::*) const
>         -> __identity<_Tp>;
> 
>     template <class _Up, class _Ap = __uncvref_t<_Up>,
>         bool _EnableIfBool = true, class = _DepIsBool<_EnableIfBool>>
>     auto operator()(bool, _Up&&) const
>         -> enable_if_t<is_same_v<_Ap, bool>, __identity<_Tp>>;
> };
> 
> ```
If we have concepts we can do so, but `__overload` is already variadic, leaving no space for sfinae...


Repository:
  rCXX libc++

https://reviews.llvm.org/D44865





More information about the cfe-commits mailing list