From b1263e8f1470c8bc3681b93e0d3516ffac90daf2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 15 Apr 2015 18:00:58 +1000 Subject: [PATCH] sphere: add ostream operator --- sphere.cpp | 13 +++++++++++++ sphere.hpp | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/sphere.cpp b/sphere.cpp index 827fc546..e8bb59be 100644 --- a/sphere.cpp +++ b/sphere.cpp @@ -27,6 +27,19 @@ sphere::sphere (point _centre, T _radius): CHECK_GE (_radius, 0); } + +//----------------------------------------------------------------------------- +template +std::ostream& +util::operator<< (std::ostream &os, sphere s) +{ + return os << "sphere(" << s.centre << ',' << s.radius << ')'; +} + +template std::ostream& util::operator<< (std::ostream&, sphere<2,float>); +template std::ostream& util::operator<< (std::ostream&, sphere<3,float>); + + //----------------------------------------------------------------------------- template struct util::sphere<2,float>; template struct util::sphere<3,float>; diff --git a/sphere.hpp b/sphere.hpp index 2896d64d..124d691f 100644 --- a/sphere.hpp +++ b/sphere.hpp @@ -19,6 +19,8 @@ #include "point.hpp" +#include + namespace util { template struct sphere { @@ -28,6 +30,9 @@ namespace util { T radius; }; + template + std::ostream& operator<< (std::ostream&, sphere); + typedef sphere<2,float> sphere2f; typedef sphere<3,float> sphere3f; }