1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <vector>
#include <algorithm>
template<typename T>
class Vector : public std::vector<T> // pour l'exemple, apres faudrait encapsuler proprement
{
template <typename Type>
class MultValue
{
private:
Type Factor;
public:
MultValue ( const Type& _Val )
: Factor ( _Val )
{
}
int operator ( ) ( Type& elem ) const
{
return elem * Factor;
}
};
public:
template<typename Param>
Vector<T> operator * (const Param & p)
{
Vector<T> r;
r.reserve(size());
std::transform(begin(), end(), r.begin(), MultValue<Param>(p));
return r;
}
};
int main()
{
Vector<int> v, w;
w = v*3;
} |