示例#1
0
Vector<T>& Vector<T>::operator+=(const Vector<T> &a)
{
    if ( a.size() != this->size())
    {
#ifdef USE_EXCEPTION
        throw WrongSize(this->size(),a.size()) ;
#else
        Error error("Vector<T>::operator+=(Vector<T>&)");
        error << "Vector<T> a += Vector<T> b different sizes, a = " << size() << ", b = " << a.size() ;
        error.fatal() ;
#endif
    }
    const int sz = this->size();
    T *ptr,*aptr ;
    ptr = this->x-1 ;
    aptr = a.x-1 ;
    for (int i = sz; i >0; --i)
        *(++ptr) += *(++aptr) ;

    return *this;
}
示例#2
0
T operator*(const Vector<T> &a,const Vector<T> &b)
{
    if ( a.size() != b.size() )
    {
#ifdef USE_EXCEPTION
        throw WrongSize(a.size(),b.size()) ;
#else
        Error error("Vector<T>::operator=(Vector<T>&)");
        error << "Vector<T> a = Vector<T> b different sizes, a = " << a.size() << ", b = " << b.size() ;
        error.fatal() ;
#endif
    }

    int i, sz = a.size();
    T prod, zero = (T)0;
    T *aptr,*bptr ;
    aptr = a.x-1 ;
    bptr = b.x-1 ;
    prod = zero ;
    for (i = sz ; i > 0; --i)
        prod += (*(++aptr)) * (*(++bptr)) ;

    return prod;
}
	/// Determine if this M_PDU matches expected parameters.
	/// @param expectedSize The intended size of the unit.
	/// @throw WrongSize If getUnitLength() is different than expectedSize.
	void throwIfInvalid(const size_t expectedSize) {
		if ( expectedSize != getUnitLength() )
			throw WrongSize(WrongSize::msg(typeStr(), expectedSize, getUnitLength()));
	}