Phillip,
This will work, but for some reason the indirect_array has the contradiction that although it provides only const iterators (hence doesn't allow you to change the data in the container), it does return non-const reference (so you can change the container by indexing or by std algorithms using Ralf's suggestion).
I am not sure about the design decision and whether this should be filed as a bug (the indirect_array concept declares the iterator constant as well, so why return non-const reference?). If the concept is to be made consistent, non-const reference may not be allowed (your code and Ralf's may not work in the future).
On the other hand if constness is forced, it may break many peoples' code. After all why should the indirect_array be immutable? Maybe the simplest thing is that we just provide regular iterators and change the concept as well.
Nevertheless, what seems like complying with the concept and I find unlikely to change is:
ublas::indirect_array<vector_type> ia(data.size(), data);
used like:
#include <boost/numeric/ublas/storage.hpp>
#include <vector>
namespace ublas = boost::numeric::ublas;
typedef std::vector<std::size_t> vector_type;
int main() {
vector_type data;
for (std::size_t i=0; i!=10; i++) data.push_back(i);
ublas::indirect_array<vector_type> ia(data.size(), data);
for (std::size_t i=0; i!=10; i++) std::cout << ia(i) << std::endl;
return 0;
}
Best,
Nasos
> Date: Thu, 29 Jul 2010 08:48:52 +0200
> From: Ralf.Denzer@web.de
> To: ublas@lists.boost.org
> Subject: Re: [ublas] submatrix with indexvector
>
> Hi Philipp,
>
> > ublas::indirect_array<> l_idx(data.size());
> > std::copy(data.begin(), data.end(), l_idx.begin());
>
> I do usually:
>
> std::copy(data.begin(), data.end(), &l_idx(0));
>
> Bye
>
> Ralf
> ___________________________________________________________
> WEB.DE DSL ab 19,99 Euro/Monat. Bis zu 150,- Euro Startguthaben und
> 50,- Euro Geldprämie inklusive! https://freundschaftswerbung.web.de
> _______________________________________________
> ublas mailing list
> ublas@lists.boost.org
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: nasos_i@hotmail.com