Adds std::same_as to libc++. Since there aren't clang-format rules for requires-expressions, I'll need to disable the formatter in certain areas.
Details
Diff Detail
Event Timeline
| libcxx/include/concepts | ||
|---|---|---|
| 149 | You are missing the uglification of all namens throughout the code. Mind not in Tests. T -> _Tp | |
This looks already quite good.
There are some pecularities of standard implementations that need to be considered. I started with the easy parts recently here
| libcxx/include/concepts | ||
|---|---|---|
| 150 | 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 | |
| libcxx/test/std/concepts/lang/same_as.pass.cpp | ||
| 9 | This test is only valid in C++20 so you should add that // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 | |
| 12 | Usually there is a comment about what is tested here template<class T, class U> | |
| libcxx/include/concepts | ||
|---|---|---|
| 150 | 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 | |
Missing a bunch of "Add a new header" changes (https://github.com/llvm/llvm-project/blob/master/libcxx/NOTES.TXT#L19-L29).
| libcxx/include/concepts | ||
|---|---|---|
| 9 | Shouldn't this line have the same length as line 2? | |
| 140 | #pragma GCC system header? https://github.com/llvm/llvm-project/blob/master/libcxx/include/any#L91-L93 | |
| 146 | Should this also guard with defined(__cpp_concepts) && __cpp_concepts >= 201811L? There are a great many compiler (version)s with C++20 mode that don't implement concepts - I assume libc++ wants to continue supporting them. | |
| 150 | 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.) | |
| libcxx/test/std/concepts/lang/same_as.pass.cpp | ||
| 82 | I think we can trust a C++20 compiler to implement C++11 correctly and accept >> here without the space ;) | |
| 154 | libc++ tests always use int main(int, char**) { (something something freestanding - I don't recall the details) | |
| 190 | There's tons of coverage here for class types and reference types. What about void, function types, pointers, arrays, pointers-to-members? (I don't know about clang/libc++, but the MSVC STL tests for type traits tend to _be_ the tests for compiler intrinsics used to implement those traits, so we consequently cover everything under the sun.) | |
| 191 | libc++ tests also always explicitly return 0. (Ditto freestanding yada yada) | |
For what its worth, I found some time today to cleanup what I had already done with @CaseyCarter old implementation D49118 (common_type and common_reference were missing).
I havent yet implemented swap as that should be handled consistently with the other CPOs when implementing ranges.
Feel free to salvage as much as you like
| libcxx/include/concepts | ||
|---|---|---|
| 150 | You can also use _IsSame which should pick the best possible definition for you. | |
| libcxx/test/std/concepts/lang/same_as.pass.cpp | ||
|---|---|---|
| 47 | Out of curiosity should that be T1 t1; and below T2 t2; | |
| 189 | Nitpick, if we go for all the different qualifiers/references there should be a test for volatile to // Checks std::same_as<volatile T, volatile T> is true
CheckSameAs<std::add_volatile>();
` | |
| 230 | Same as above volatile is missing | |
LGTM. I'll resign rather than approving so the "real" approvers won't be confused and never look at this.
| libcxx/test/std/concepts/lang/same_as.pass.cpp | ||
|---|---|---|
| 47 | It probably could be, but it doesn't make a difference for this test. | |
Shouldn't this line have the same length as line 2?