[libcxx-commits] [PATCH] D74291: [libcxx] Adds [concept.same]

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Feb 9 23:01:56 PST 2020


zoecarver added inline comments.


================
Comment at: libcxx/include/concepts:149
+template <class T, class U>
+concept __same_as_impl = __is_same(T, U);
+
----------------
CaseyCarter wrote:
> miscco wrote:
> > miscco wrote:
> > > Thinking about it more, this will not work with other compilers such as MSVC. You should seither check the Compiler aka #ifdef __clang__ or the existence of the keyword
> > As the code was not displayed properly
> > 
> > ```
> > template <class _Tp, class _Up>
> > concept __same_as_impl =
> > #ifdef __clang__
> >     __is_same(_Tp, _Up);
> > #else
> >     _VSTD::is_same_v<_Tp, _Up>;
> > #endif
> > ```
> Clang has supported `__is_same` since roughly clang 3. I didn't remember precisely how far back libc++ supports, but it's not that far - so assuming `__is_same` when `__clang__` is fine. GCC since version 6 supports `__is_same_as` with the same semantics. (MSVC has none of the above, but `std::is_same_v` is one of the type traits we recognize and implement directly in the compiler front end, so it's ideal to simply use `is_same_v` with MSVC.)
> 
You can also use `_IsSame` which should pick the best possible definition for you. 


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

https://reviews.llvm.org/D74291





More information about the libcxx-commits mailing list