Skip to content

Commit

Permalink
Make std::{shared,unique}_ptr ostreamable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eelis committed Oct 19, 2016
1 parent c3fb467 commit a281777
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions prelude/more_ostreaming.hpp
Expand Up @@ -337,6 +337,31 @@ inline std::basic_ostream<Ch, Tr> &

#endif

#if __cplusplus >= 201103

#include <memory>

template<typename Ch, typename Tr, typename T>
inline std::basic_ostream<Ch, Tr> &
operator<<(std::basic_ostream<Ch, Tr> & o, std::unique_ptr<T> const & p)
{
if (p) o << p.get();
else o << "nullptr";
return o;
}

template<typename Ch, typename Tr, typename T>
inline std::basic_ostream<Ch, Tr> &
operator<<(std::basic_ostream<Ch, Tr> & o, std::shared_ptr<T> const & p)
{
if (p) o << p.get();
else o << "nullptr";
return o;
}

#endif


#endif // header guard

#ifdef MORE_OSTREAMING_TEST
Expand Down

0 comments on commit a281777

Please sign in to comment.