Hello all.
I am trying to implement a fixed_array / fixed_vector couple and have come across a difficulty. My fixed_array class is pretty similar to the bounded_array class, but with the size_t size_ member thrown away and with the necessary changes in functions returning or requiring this variable. While most things work well in the unit tests, the difficulty arises when assigning to a projection, i.e.:
ublas::fixed_vector<double, 3> v1, v2;
project (v1, ublas::range(0,1)) = project (v2, ublas::range(0,1));
Tracing back the function calls I get the following flow:
1. basic_range (size_type start, size_type stop) (constructor of the second ublas::range)
2. vector_range (vector_type &data, const range_type &r) (constructor of the second ublas::range) - requests v2.size()
3. basic_range (size_type start, size_type stop) (constructor of the first ublas::range)
4. vector_range (vector_type &data, const range_type &r) (constructor of the first ublas::range) - requests v1.size()
5. vector_range &operator = (const vector_range &vr)
6. vector (const vector_expression<AE> &ae) (implicit vector construction from a vector_range)
7. fixed_array (size_type size)
8. vector_assign (V &v, const vector_expression<E> &e, dense_proxy_tag)
9. indexing_vector_assign (V &v, const vector_expression<E> &e)
10. size_type size (BOOST_UBLAS_SAME (v.size (), e ().size ()));
and in line 10 is where the BOOST CHECK fails. What happens is that v.size() (which is temporary of a fixed_vector<double, 3>) has of course a size of 3, while e().size() has a size of 1 (as been the range(0,1).
In order to come over this error I changed my fixed_vector typedefs to instead of using self_type as the
vector_temporary_type, to use a bounded_vector<T, N>, which does the trick (since bounded_vector is not actually fixed and can be resized to be of the same size as the vector_range).
Although in this case the same problem arises when creating a vector with storage container the fixed_array (i.e. vector<double, fixed_array<double, 3> > ), where the vector_temporary_type is not so easy to change.
So my questions are:
A. Is there an elegant way to alter the vector_temporary type in ublas::vector given only the storage type?
B. Would it be a mess to change (10.) BOOST_UBLAS_SAME to something like BOOST_UBLAS_LESS?
C. Is there any other workaround through the traits mechanism I am not aware of?
And finally are the developers interested in a fixed_array / fixed_vector, if it gets to work? I think it will provide some nice ground for metaprograms and a few other convenience tricks that can come handy.
Thanks in advance
Nasos Iliopoulos
Windows Live: Keep your friends up to date with what you do online. Find out more.