A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../iterator/../concepts/same_as.html below:

std::same_as - cppreference.com

template< class T, class U >
concept same_as = /* see below */;

(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.

[edit] Possible implementation
namespace detail
{
    template< class T, class U >
    concept SameHelper = std::is_same_v<T, U>;
}
 
template< class T, class U >
concept same_as = detail::SameHelper<T, U> && detail::SameHelper<U, T>;
[edit] Example
#include <concepts>
#include <iostream>
 
template<typename T, typename ... U>
concept either = (std::same_as<T, U> || ...);
 
template<typename T>
concept is_printable = std::integral<T> || std::floating_point<T> ||
    either<std::remove_cvref_t<std::remove_pointer_t<std::decay_t<T>>>, char, wchar_t>;
 
void println(is_printable 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]
[edit] References
[edit] See also checks if two types are the same
(class template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4