Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2005-03-15 13:49:07


> template<typename T>
> struct print_log_value {
> void operator()( std::ostream& ostr, T const& t )
> {
> #if !BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1310))
> // Show all possibly significant digits (for example, 17 for
64-bit
> double).
> if( std::numeric_limits<T>::is_specialized &&
> std::numeric_limits<T>::radix == 2 )
> ostr.precision(2 + std::numeric_limits<T>::digits * 301/1000);
> #endif
> ostr << t; // by default print the value
> }
> };

Would solution like following will cover all FPTs?

template<typename is_spec>
struct set_log_precision { static _( std::ostream& ostr ) {} }

// Show all possibly significant digits (for example, 17 for 64-bit double).
template<>
struct set_log_precision<true> {
  static _( std::ostream& ostr )
  {
    ostr.precision(2 + std::numeric_limits<T>::digits * 301/1000);
  }
}

template<typename T>
struct print_log_value {
     void operator()( std::ostream& ostr, T const& t )
     {
         set_log_precision<std::numeric_limits<T>::is_specialized &&
std::numeric_limits<T>::radix == 2>::_( ostr );

         ostr << t;
     }
};

Gennadiy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk