Robert Ramey wrote: > Actually this suits my current need. It compiles in my environment. > Does this mean its universally OK?. I thought I had seen something > like this before but couldn't find it in any of my references so I had been > trying something variations on:
If you look at the regression tests you will find a couple of failures. On windows Borland and MSVC6/7.0 cannot be initialised for anything but the basic types (int, double, const char *, etc) The two tests that fail are based on array< std::string >. If array< const char *> is substituted they initialise correctly and pass the tests. So yes, this is correct for conforming compilers, and so long as you are not using user defined types will work even on the current compilers that are broken. > Presumably boost::array was motivated by the desire to make > an array look like a container - which is what I wanted. I found > it unsatisfactory because of the copying. Would it not be interesting > to make an equivalent that would take either an array reference > or a pointer and give it a ful container like interface so that one could > do something like: > > const int array[] = {1, 2, 3, 4}; > boost::container_facade<int> cfa(array); > std::copy(cfa.begin(), cfa.end(), ...); Ok, here's the awkward question. How do we determine cfa.end()? boost::array works with fixed size arrays, so always knows the size of the array. If you want a variable sized array, then the standard library already provides this with std::vector. So I assume you want either a/ a fixed-size array, of size unknown at compile time. or b/ an array fixed at compile time, owned outside the container, but supplying a container-like wrapper? (a) is certainly possible, and something I have considered implementing several times myself. However, given std::vector covers so much of the need I find it hard to justify writing an extra class. AFAICT, the main difference is the lack of push_back, pop_back, insert and erase. (b) I am not sold on, as all other containers I am familiar with own their contents. I feel this change of idiom might confuse otherwise clear code. Also note that one of the listed advantages of boost::array is that it does indeed copy-by-value. This means you need to pass-by-reference to achieve 'traitional' array passing, but have a new facility available that some of us do find useful <g> -- AlisdairM _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost