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

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 26 19:49:10 PDT 2018


EricWF added inline comments.


================
Comment at: include/variant:1109
 
+#define _LIBCPP_VARIANT_BOOLEAN_CONVERSION(bool_type)                    \
+    template <class... _Types>                                           \
----------------
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>>;
};

```


Repository:
  rCXX libc++

https://reviews.llvm.org/D44865





More information about the cfe-commits mailing list