mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Switch //common to use C++20 concepts. (#3665)
This removes the use of `enable_if` and tries to adopt concepts instead of type traits when available. The `ostream.h` change is a bit subtle as it adds a restriction not previously in place -- that the stream is *contvertible* to `std::ostream` as well as having it as a base class. This seems to match the intent of the code. The `hashing.h` code adds an implementation detail concept, and so I've also clarified that the dispatch namespace is an internal one that isn't part of the public API.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <concepts>
|
||||
|
||||
#include "llvm/ADT/Sequence.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
@@ -339,7 +339,8 @@ auto PrintFullWidthHex(llvm::raw_ostream& os, T value) {
|
||||
static_cast<uint64_t>(value));
|
||||
}
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
|
||||
template <typename T>
|
||||
requires std::integral<T>
|
||||
auto operator<<(llvm::raw_ostream& os, HashedValue<T> hv)
|
||||
-> llvm::raw_ostream& {
|
||||
os << "hash " << hv.hash << " for value ";
|
||||
@@ -347,9 +348,8 @@ auto operator<<(llvm::raw_ostream& os, HashedValue<T> hv)
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename T, typename U,
|
||||
typename = std::enable_if_t<std::is_integral_v<T>>,
|
||||
typename = std::enable_if_t<std::is_integral_v<U>>>
|
||||
template <typename T, typename U>
|
||||
requires std::integral<T> && std::integral<U>
|
||||
auto operator<<(llvm::raw_ostream& os, HashedValue<std::pair<T, U>> hv)
|
||||
-> llvm::raw_ostream& {
|
||||
os << "hash " << hv.hash << " for pair of ";
|
||||
|
||||
Reference in New Issue
Block a user