From 2ad93a38dd23a0c8032522850e401917e80050da Mon Sep 17 00:00:00 2001 From: menete Date: Tue, 14 Nov 2017 17:14:20 +0100 Subject: [PATCH] Iosfwd (#586) * Solves #567 with approach * adds a little testing to not_null ostream --- include/gsl/pointers | 2 +- tests/notnull_tests.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/gsl/pointers b/include/gsl/pointers index 83ac9ea..cff2513 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -21,7 +21,7 @@ #include -#include +#include #include #include diff --git a/tests/notnull_tests.cpp b/tests/notnull_tests.cpp index 6111553..6c841f0 100644 --- a/tests/notnull_tests.cpp +++ b/tests/notnull_tests.cpp @@ -129,6 +129,38 @@ TEST_CASE("TestNotNullConstructors") std::make_shared(10)); // shared_ptr is nullptr assignable } +template +void ostream_helper(T v) +{ + not_null p(&v); + { + std::ostringstream os; + std::ostringstream ref; + os << p; + ref << &v; + CHECK(os.str() == ref.str()); + } + { + std::ostringstream os; + std::ostringstream ref; + os << *p; + ref << v; + CHECK(os.str() == ref.str()); + } +} + +TEST_CASE("TestNotNullostream") +{ + ostream_helper(17); + ostream_helper(21.5f); + ostream_helper(3.4566e-7f); + ostream_helper('c'); + ostream_helper(0x0123u); + ostream_helper("cstring"); + ostream_helper("string"); +} + + TEST_CASE("TestNotNullCasting") { MyBase base;