From f50bbd72c47caeea55fec4d1b7a69e9da1b4210a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 24 Nov 2014 17:10:46 +0100 Subject: [PATCH] Use iformat and Input_rep instead of an additional function --- .../benchmark/Stream_support/read_doubles.cpp | 13 +++++- Stream_support/include/CGAL/IO/io.h | 41 +++++++++---------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Stream_support/benchmark/Stream_support/read_doubles.cpp b/Stream_support/benchmark/Stream_support/read_doubles.cpp index 453524200fc..5ea4ca2a220 100644 --- a/Stream_support/benchmark/Stream_support/read_doubles.cpp +++ b/Stream_support/benchmark/Stream_support/read_doubles.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -27,7 +28,7 @@ int main(int argc, char* argv[]) std::cerr << "operator"<< std::endl; t.start(); for(int i=0; i> d; sum+= d; } t.stop(); @@ -67,6 +68,16 @@ int main(int argc, char* argv[]) sum+= d; } t.stop(); + } + + if(choice == 4){ + std::cerr << "iformat"<< std::endl; + t.start(); + for(int i=0; i> CGAL::iformat(d); + sum+= d; + } + t.stop(); } std::cerr.precision(17); std::cerr << "sum = " << sum << std::endl; diff --git a/Stream_support/include/CGAL/IO/io.h b/Stream_support/include/CGAL/IO/io.h index 137bb4c83dd..7643a33fe0b 100644 --- a/Stream_support/include/CGAL/IO/io.h +++ b/Stream_support/include/CGAL/IO/io.h @@ -91,6 +91,25 @@ public: std::istream& operator()( std::istream& in) const { return (in >> t); } }; + +#if defined( _MSC_VER ) && ( _MSC_VER > 1600 ) && (! defined( CGAL_NO_IFORMAT_DOUBLE )) +template <> +class Input_rep { + double& t; +public: + //! initialize with a reference to \a t. + Input_rep( double& tt) : t(tt) {} + //! perform the input, calls \c operator\>\> by default. + std::istream& operator()( std::istream& is) const + { + std::string s; + is >> s; + sscanf(s.c_str(), "%lf", &t); + return is; + } +}; +#endif + /*! \relates Input_rep \brief stream input to the \c Input_rep calls its \c operator(). */ @@ -168,28 +187,6 @@ bool is_binary(std::ios& i); -#ifdef CGAL_GENERIC_EXTRACT - template - inline std::istream& extract(std::istream& is, T &t) - { - is >> t; - return is; - } - - template <> -#endif - - inline std::istream& extract(std::istream& is, double &d) -{ -#if defined( _MSC_VER ) && ( _MSC_VER > 1600 ) - std::string s; - is >> s; - sscanf(s.c_str(), "%lf", &d); -#else - is >> d; -#endif - return is; -} template < class T > inline