Last active
February 1, 2017 08:52
-
-
Save zmij/66e66481f4143ea4ad2d to your computer and use it in GitHub Desktop.
Check for std::iostream input/output operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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