[libcxx-commits] [PATCH] D67900: [libc++] Use builtin type traits whenever possible

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 7 13:29:14 PDT 2019


zoecarver marked an inline comment as done.
zoecarver added inline comments.


================
Comment at: libcxx/include/type_traits:550
+template <class _Tp, class _Up>
+using is_same = _BoolConstant<__is_same(_Tp, _Up)>;
+
----------------
rsmith wrote:
> Nice idea. Is this conforming? Consider this somewhat-contrived example:
> 
> ```
> template<typename T> struct A {
>   void f(is_same<T, int>) {}
>   void f(is_same<T, float>) {}
>   void f(false_type) {}
>   void g() { f(disjunction<is_same<T, int>, is_same<T, float>, false_type>()); }
> };
> ```
> 
> With a class template `is_same`, `g()` calls the version of `f` corresponding to the "right" option, but with the alias template version, instantiating `A<T>` is ill-formed because multiple signatures of `f` collide.
Arg, you are correct :) 

The following seems to work, though:
```
template<bool _V>
struct m_bool_constant : integral_constant<bool, _V> { };

template <class _Tp, class _Up>
using m_is_same = m_bool_constant<__is_same(_Tp, _Up)>;

template<typename T> struct A {
  void f(m_is_same<T, int>) {}
  void f(m_is_same<T, float>) {}
  void f(false_type) {}
  void g() { f(disjunction<m_is_same<T, int>, m_is_same<T, float>, false_type>()); }
};

A<int> a{ };
```

What do you think of the above code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67900





More information about the libcxx-commits mailing list