STL wrapper, looking for a more elegant solution
"seanconsoleguy" <[email protected]> Thu, 09 Mar 2006 02:07:53 -0000
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Message-ID | <[email protected]> |
I have a class for representing a mathematical 2-D vector class
which extends the std::valarray, templated for different precision
floating point numbers. The float specification code has a couple
places where I would like it to be more elegant...the one
marked 'ugly' is not so bad, but I really don't like the one
marked 'UGLY!'. Any thoughts appreciated (note: this is me messing
around, not production code).
template <>
class vector2<float> : public std::valarray<float>{
public:
vector2( float x = 0.0f, float y =
0.0f ):std::valarray<float>(dim){
// ugly
// calls the valarray operator[] to initialize
the elements
(*this)[0] = x;
(*this)[1] = y;
}
vector2(const vector2<float>& rhs):std::valarray<float>
(*this){
};
vector2<float>& operator=(const vector2<float>& rhs){
// UGLY!
static_cast<std::valarray<float>&>(*this) =
static_cast<const std::valarray<float>&>(rhs);
return *this;
};
private:
const static size_t dim = 2;
};
Thanx,
Sean
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/cppug/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/