Boost logo

Ublas :

From: Darin DeForest (darin_at_[hidden])
Date: 2005-08-24 14:40:45


I'm trying to understand the difference betwen these too snippets of code

snippet #1

const int numberOfPoints = 4
ublas::vector<int> processed( zero_vector<int>(numberOfPoints ) );

snippet #2

const int numberOfPoints = 4
ublas::vector<int> processed( scalar_vector<int>(numberOfPoints, 0) );

The problem is when I perform the following

processed[ 0 ] = 3;

I get an compiler error for code snippet #1, i.e.
         error C2109: subscript requires array or pointer type

I suspect that in snippet 1, processed is defining a function prototype with a parameter of zero_vector<int>, while in snippet #2, it is vector that is getting initialized to zero.

What makes this more interesting is when I change this to initialization by assignment

ublas::vector<int> processed = ( zero_vector<int>(numberOfPoints, 0) );

This error message goes away, but now I get error messages on these type of definitions

ublas::vector<int> vector1;

error C2668: 'std::sqrt' : ambiguous call to overloaded function
         \ublas\boost\boost_1_33_0\boost\numeric\ublas\traits.hpp(94) : error C2668: 'std::sqrt' : ambiguous call to overloaded function
        C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(200): could be 'double sqrt(double)'
        C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(578): or 'float sqrt(float)'
        C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(626): or 'long double sqrt(long double)'
        while trying to match the argument list '(const int)'
       \ublas\boost\boost_1_33_0\boost\numeric\ublas\traits.hpp(93) : while compiling class-template member function 'boost::numeric::ublas::scalar_traits<T>::value_type boost::numeric::ublas::scalar_traits<T>::sqrt(boost::numeric::ublas::scalar_traits<T>::const_reference)'
        with
        [
            T=int
        ]
        \ublas\boost\boost_1_33_0\boost\numeric\ublas\traits.hpp(125) : see reference to class template instantiation 'boost::numeric::ublas::scalar_traits<T>' being compiled
        with
        [
            T=int
        ]
        \boost\boost_1_33_0\boost\numeric\ublas\vector.hpp(43) : see reference to class template instantiation 'boost::numeric::ublas::type_traits<T>' being compiled
        with
        [
            T=int
        ]

If I remove the "processed" variable declaration/initialization, these error messages go away indicating nothing is wrong with the definition of vector1.

So the moral of this story is that zero_vector seems to be treated funny for other vector constructors, and that using it as an r-value in assignment causes other weird things to happen, which isn't obvious. Using scalar_vector these problems don't occur, and I still can use "vector<int> vector1; " constructors