Use iformat and Input_rep<double> instead of an additional function

This commit is contained in:
Andreas Fabri 2014-11-24 17:10:46 +01:00
parent 36f1514957
commit f50bbd72c4
2 changed files with 31 additions and 23 deletions

View File

@ -6,6 +6,7 @@
#include <fstream>
#include <string>
#include <CGAL/Timer.h>
#include <CGAL/IO/io.h>
#include <boost/lexical_cast.hpp>
@ -27,7 +28,7 @@ int main(int argc, char* argv[])
std::cerr << "operator"<< std::endl;
t.start();
for(int i=0; i<n; i++){
CGAL::extract(std::cin, d);
std::cin >> d;
sum+= d;
}
t.stop();
@ -68,6 +69,16 @@ int main(int argc, char* argv[])
}
t.stop();
}
if(choice == 4){
std::cerr << "iformat"<< std::endl;
t.start();
for(int i=0; i<n; i++){
std::cin >> CGAL::iformat(d);
sum+= d;
}
t.stop();
}
std::cerr.precision(17);
std::cerr << "sum = " << sum << std::endl;
std::cerr << t.time() << "sec."<< std::endl;

View File

@ -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> {
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 <typename T>
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