$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Sean Parent (sparent_at_[hidden])
Date: 2001-12-04 01:36:14
I ran into the following problem with array_traits.hpp (boost 1.26.0) and
CodeWarrior 7.0 (stock compilers - this code is distilled for this bug
report). Compiling this code causes the IDE to exit with an internal
compiler error:
---
#include <iostream>
#include <boost/array_traits.hpp>
template <typename R>
typename boost::array_traits<R>::iterator get_end(R& range)
{
return boost::end(range);
}
int main()
{
int array[] = { 0, 1, 2, 3, 4, 5 };
std::cout << *(get_end(array) - 1) << std::endl;
return 0;
}
---
The problem appears to be in the array_traits specializations for arrays
(both const and non-const when the size is taken. That, combined with the
reference in get_end(R&) and boom.
The workaround I found was to change how size is taken:
template <typename T>
inline int array_size(T(&))
{
return sizeof(T) / sizeof((*((T*)(0)))[0]);
}
// In array_traits<T[sz]>
static iterator end(T (&array)[sz])
{ return array + array_size(array); }
static size_type size(T (&array)[sz])
{ return array_size(array); }
// In array_traits<T const[sz]>
static iterator end(T const (&array)[sz])
{ return array + array_size(array); }
static size_type size(T const (&array)[sz])
{ return array_size(array); }
This inline for array_size() will also work on VC++. It may be useful in
trying to do an array_traits that works with VC++.
Sean
--
Sean Parent
Sr. Computer Scientist II
Advanced Technology Group
Adobe Systems Incorporated
sparent_at_[hidden]