Skip to content

Instantly share code, notes, and snippets.

@zmij
Last active February 1, 2017 08:52
Show Gist options
  • Save zmij/66e66481f4143ea4ad2d to your computer and use it in GitHub Desktop.
Save zmij/66e66481f4143ea4ad2d to your computer and use it in GitHub Desktop.
Check for std::iostream input/output operators
template < typename T >
class has_output_operator {
template < typename U >
using helper = decltype( ::std::declval<::std::ostream&>() << ::std::declval<U>(), void() );
template < typename U = T>
static ::std::true_type test(helper<U>*);
static ::std::false_type test(...);
public:
using type = decltype(test(nullptr));
static constexpr bool value = type::value;
};
template < typename T >
class has_input_operator {
template < typename U >
using helper = decltype( ::std::declval<::std::istream&>() >> ::std::declval<U&>(), void() );
template < typename U = T>
static ::std::true_type test(helper<U>*);
static ::std::false_type test(...);
public:
using type = decltype(test(nullptr));
static constexpr bool value = type::value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment