ПК
Size: a a a
ПК
VS
ПК
LA
VS
LA
ПК
AS
ПК
VS
ПК
ПК
AS
AS
VS
AS
#include <iostream>
template<typename T>
concept Printable = requires(T a) {
std::cout << a;
};
template<typename T>
struct printable
{
enum {value = Printable<T>};
};
template<typename T>
constexpr bool printable_v = printable<T>::value;
template<typename T>
void check_printable(T value)
{
if constexpr (printable_v<T>) {
std::cout << typeid(T).name() << " is a printable type";
} else
{
std::cout << typeid(T).name() << " is not a printable type";
}
}
struct foo {};
int main() {
check_printable(10);
check_printable(foo());
}
LA
template <typename T>
auto foo() -> decltype(void(std::declval<std::ostream&>() << std::declval<T>()), smt) {
}
ПК
C
AS
template<typename T>
void check_printable(T value)
{
if constexpr (Printable<T>) {
std::cout << typeid(T).name() << " is a printable type";
} else
{
std::cout << typeid(T).name() << " is not a printable type";
}
}