Boost logo

Boost :

From: Stefan Slapeta (stefan_at_[hidden])
Date: 2005-03-15 11:40:55


Gennadiy Rozental wrote:
>
> I believe this is a compiler/STL problem. Here is snippet of offending
> code:
>
> template<typename T>
> struct print_log_value {
> void operator()( std::ostream& ostr, T const& t )
> {
> // 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);
>
> ostr << t; // by default print the value
> }
> };
>
> If I try to print C literal this function is instantiated with char [N]. And
> if fails to instantiate std::numeric_limits<char [N]>.
>
> Shouldn't numeric_limits work for any type?
>

I _think_ (correct me if I'm wrong) the problem is quite different and
related to the portability issues of BOOST_CHECK_EQUAL with C string
literals.

The code above doesn't compile on VC 7.1, either. However, the
regression tests don't show any problems with VC 7.1!! Thus, the reason
for this issue is IMO that this code isn't instantiated at all for VC
7.1 (but it _is_ for Intel) and that's very similar to the
BOOST_CHECK_EQUAL problem!

Here is a test case - it compiles on VC 7.1 and many others (but
shouldn't) but doesn't compile on EDG:

#include <limits>

template <typename T>
std::size_t test(T const& t)
{
     // this is the correct one, called by EDG
     // however, numeric_limits can't be instantiated
     // for char[N]
     return std::numeric_limits<T>()::digits;
}

std::size_t test(const char* t)
{
     // this is the one called by many others
     return 0;
}

int main(int argc, char **argv) {
     char buf[] = "asdf";
     test(buf); // we have an array, not const char*!!!
}

But there are also other (related) even more subtle overloading
errors...I'll have to look into my mailbox for those.

Stefan


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