Re: A malloc error in C++ - incorrect checksum for freed object
In message <5k249kF1pgklU1@mid.dfncis.de>, Frank Birbacher
<bloodymir.crap@gmx.net> writes
Hi!
Jerry Coffin schrieb:
There is another way: make something that acts like a vector full of
identical values:
:D Nice idea!
I thought about it: Your partial implementation needs to be completed.
This is a type of thing nobody does regularly. Thus it'll take much time
to get it correct. OTOH you only need a single iterator since
inner_product does not care about an end of the second sequence.
So you don't even need the vector part. How about just something that
acts like an iterator over an (infinite) sequence of identical values:
// Warning - untested code
template <typename T>
class IteratorToConstant {
public:
IteratorToConstant(T x) : v_(x) {}
T & operator*() const { return v_; }
IteratorToConstant & operator++() { return *this; }
IteratorToConstant & operator++(int) { return *this; }
private:
T v_;
};
Again, just a skeleton - you might want to add operator-- etc.
--
Richard Herring