On this page
std::same_as
Defined in header <concepts> |
||
---|---|---|
|
(since C++20) |
The concept same_as<T, U>
is satisfied if and only if T
and U
denote the same type.
std::same_as<T, U>
subsumes std::same_as<U, T>
and vice versa.
Possible implementation
|
Example
#include <concepts>
#include <iostream>
template<typename T, typename ... U>
concept IsAnyOf = (std::same_as<T, U> || ...);
template<typename T>
concept IsPrintable = std::integral<T> || std::floating_point<T> ||
IsAnyOf<std::remove_cvref_t<std::remove_pointer_t<std::decay_t<T>>>, char, wchar_t>;
void println(IsPrintable auto const ... arguments)
{
(std::wcout << ... << arguments) << '\n';
}
int main()
{
println("Example: ", 3.14, " : ", 42, " : [", 'a', L'-', L"Z]");
}
Output:
Example: 3.14 : 42 : [a-Z]
See also
(C++11)
|
checks if two types are the same (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/concepts/same_as