Boost logo

Ublas :

From: Nico Galoppo (nico_at_[hidden])
Date: 2006-08-12 19:54:44


Hi,

what is wrong with the following code snippet? On my compiler (msvc 8.0) it
outputs nothing, because the for loop terminates immediately.

int main()
{
        typedef ublas::coordinate_vector<double> cv_type;
        cv_type v;
        v.append_element(3, 40);
        v.append_element(5, 41);
        v.append_element(7, 42);
        v.append_element(300, 43);

        for (cv_type::iterator it = v.begin(); it != v.end(); ++it)
                std::cout << "(" << it.index() << "," << *it << ")" << std::endl;
}

The following snippet gives output, but not all elements are shown. I have the
impression that I don't understand the meaning of the different constructors
and/or the difference between the 'size' and 'non_zeros' parameters in the
coordinate_vector (size_type size, size_type non_zeros) constructor.

int main()
{
        typedef ublas::cooordinate_vector<double> cv_type;
        cv_type v(10);
        v.insert_element(3, 40);
        v.insert_element(5, 41);
        v.insert_element(7, 42);
        v.insert_element(300, 43);

        for (cv_type::iterator it = v.begin(); it != v.end(); ++it)
                std::cout << "(" << it.index() << "," << *it << ")" << std::endl;
}

Thanks!

--nico

-- 
nico galoppo von borries     @  address: 105 creel st., chapel hill
comp. graphics phd. student  @           north carolina, 27516 USA
UNC, chapel hill             @  phone: +1 (919) 962-1898 (office)
                              @         +1 (919) 942-7609 (home)
                              @  email: nico at cs dot unc dot edu
                              @  homepage: http://www.cs.unc.edu/~nico