Allow usage on platforms not providing iostreams (#935)

Closes #933.
This commit is contained in:
mtnpke 2020-10-28 23:37:02 +01:00 committed by GitHub
parent 6f4529395c
commit 736b62a838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,11 +20,15 @@
#include <gsl/gsl_assert> // for Ensures, Expects #include <gsl/gsl_assert> // for Ensures, Expects
#include <algorithm> // for forward #include <algorithm> // for forward
#include <iosfwd> // for ptrdiff_t, nullptr_t, ostream, size_t #include <cstddef> // for ptrdiff_t, nullptr_t, size_t
#include <memory> // for shared_ptr, unique_ptr #include <memory> // for shared_ptr, unique_ptr
#include <system_error> // for hash #include <system_error> // for hash
#include <type_traits> // for enable_if_t, is_convertible, is_assignable #include <type_traits> // for enable_if_t, is_convertible, is_assignable
#if !defined(GSL_NO_IOSTREAMS)
#include <iosfwd> // for ostream
#endif // !defined(GSL_NO_IOSTREAMS)
namespace gsl namespace gsl
{ {
@ -116,12 +120,14 @@ auto make_not_null(T&& t) noexcept {
return not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)}; return not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)};
} }
#if !defined(GSL_NO_IOSTREAMS)
template <class T> template <class T>
std::ostream& operator<<(std::ostream& os, const not_null<T>& val) std::ostream& operator<<(std::ostream& os, const not_null<T>& val)
{ {
os << val.get(); os << val.get();
return os; return os;
} }
#endif // !defined(GSL_NO_IOSTREAMS)
template <class T, class U> template <class T, class U>
auto operator==(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() == rhs.get())) -> decltype(lhs.get() == rhs.get()) auto operator==(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() == rhs.get())) -> decltype(lhs.get() == rhs.get())