scaled1d conversion operator: doesn't behave as expected
Walter Daems <[email protected]> Mon, 26 Apr 2004 09:43:28 +0200
| Newsgroups | gmane.comp.lib.mtl.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all, The conversion operator "operator Vector&()" in scaled1d.h does not behave as I expected (maybe my expectations were wrong..., if so, don't hesitate to correct me): instead of returning a scaled vector, it returns the original one. Anyway, I propose to make a change to scaled1d.h, removing the confusing behavior of the conversion operator. The disadvantage is O(nnz()) instead of O(1), but O(1) for an operation that (in my opinion) is not very useful makes less sense than spending O(nnz()) on a useful operation. The patch in attachment shows exactly what my proposal is. bye, Walter. _______________________________________________ This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/
patch_scaled1d_convop
(text/plain, 1.1 KB)
*** orig/scaled1D.h 2004-04-25 23:16:59.000000000 +0200
--- adpt/scaled1D.h 2004-04-26 09:32:13.000000000 +0200
***************
*** 124,135 ****
//: Destructor
inline ~scaled1D() { }
/**@name Access Methods */
! //: Access base containers
! inline operator Vector&() { return rep; }
//: Return a const iterator pointing to the beginning of the vector
//!wheredef: Container
inline const_iterator begin() const {
return const_iterator(rep.begin(), scale);
--- 124,145 ----
//: Destructor
inline ~scaled1D() { }
/**@name Access Methods */
! //: Conversion operator
! inline operator Vector() {
! Vector v( rep.size() );
!
! typename Vector::const_iterator it = rep.begin();
! const typename Vector::const_iterator endit = rep.end();
!
! for ( ; it != endit; ++it )
! v[ it.index() ] = *it * scale;
!
! return v;
! }
//: Return a const iterator pointing to the beginning of the vector
//!wheredef: Container
inline const_iterator begin() const {
return const_iterator(rep.begin(), scale);