Replication of same behaviour without using decltype

Sure, here’s an implementation using sizeof:

template<class T, class = std::false_type>
struct is_streamable_object : std::false_type {};

template<class T>
struct is_streamable_object<T,
    std::bool_constant<sizeof(std::cerr << std::declval<T>()) == 0>> : std::true_type {};


Other keywords you could use include alignof, noexcept, typeid, and explicit (the last since C++20).

Essentially, you want to perform expression SFINAE, which requires constructing an expression that is not to be evaluated. The operators that allow constructing unevaluated expressions are those mentioned above plus decltype (which you do not want to use) and requires (C++20).

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top