Add opt-in c++11 stream insertable check. (#877)

* Add opt-in c++11 stream insertable check.

To opt-in, define CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK.

Opt-in fixes #872 and should fix #757 as well.
This commit is contained in:
Sergey Semushin
2017-04-05 10:53:10 +03:00
committed by Martin Hořeňovský
parent 0354d50278
commit 94425ad59b
3 changed files with 68 additions and 11 deletions

View File

@@ -72,6 +72,7 @@ namespace Detail {
extern const std::string unprintableString;
#if !defined(CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK)
struct BorgType {
template<typename T> BorgType( T const& );
};
@@ -90,6 +91,20 @@ namespace Detail {
static T const&t;
enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) };
};
#else
template<typename T>
class IsStreamInsertable {
template<typename SS, typename TT>
static auto test(int)
-> decltype( std::declval<SS&>() << std::declval<TT>(), std::true_type() );
template<typename, typename>
static auto test(...) -> std::false_type;
public:
static const bool value = decltype(test<std::ostream,const T&>(0))::value;
};
#endif
#if defined(CATCH_CONFIG_CPP11_IS_ENUM)
template<typename T,