⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valarray

📁 C语言库函数的原型,有用的拿去
💻
📖 第 1 页 / 共 3 页
字号:
	{	// return scalar / valarray
	_VALOP(_Ty, _Right.size(), _Left / _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator%(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray % scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] % _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator%(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar % valarray
	_VALOP(_Ty, _Right.size(), _Left % _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator+(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray + scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] + _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator+(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar + valarray
	_VALOP(_Ty, _Right.size(), _Left + _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator-(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray - scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] - _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator-(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar - valarray
	_VALOP(_Ty, _Right.size(), _Left - _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator^(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray ^ scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] ^ _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator^(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar ^ valarray
	_VALOP(_Ty, _Right.size(), _Left ^ _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator&(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray & scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] & _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator&(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar & valarray
	_VALOP(_Ty, _Right.size(), _Left & _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator|(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray | scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] | _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator|(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar | valarray
	_VALOP(_Ty, _Right.size(), _Left | _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator<<(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray << scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] << _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator<<(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar << valarray
	_VALOP(_Ty, _Right.size(), _Left << _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator>>(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray >> scalar
	_VALOP(_Ty, _Left.size(), _Left[_Idx] >> _Right);
	}

template<class _Ty> inline
	valarray<_Ty> operator>>(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar >> valarray
	_VALOP(_Ty, _Right.size(), _Left >> _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator&&(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray && scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] && _Right);
	}

template<class _Ty> inline
	_Boolarray operator&&(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar && valarray
	_VALOP(_Bool, _Right.size(), _Left && _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator||(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray || scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] || _Right);
	}

template<class _Ty> inline
	_Boolarray operator||(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar || valarray
	_VALOP(_Bool, _Right.size(), _Left || _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator*(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray * valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] * _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator/(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray ? valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] / _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator%(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray % valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] % _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator+(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray + valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] + _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator-(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray - valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] - _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator^(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray ^ valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] ^ _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator&(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray & valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] & _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator|(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray | valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] | _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator<<(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray << valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] << _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> operator>>(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray >> valarray
	_VALOP(_Ty, _Left.size(), _Left[_Idx] >> _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator&&(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray && valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] && _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator||(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray || valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] || _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator==(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray == scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] == _Right);
	}

template<class _Ty> inline
	_Boolarray operator==(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar == valarray
	_VALOP(_Bool, _Right.size(), _Left == _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator==(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray == valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] == _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator!=(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray != scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] != _Right);
	}

template<class _Ty> inline
	_Boolarray operator!=(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar != valarray
	_VALOP(_Bool, _Right.size(), _Left != _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator!=(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray != valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] != _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator<(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray < scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] < _Right);
	}

template<class _Ty> inline
	_Boolarray operator<(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar < valarray
	_VALOP(_Bool, _Right.size(), _Left < _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator<(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray < valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] < _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator>(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray > scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] > _Right);
	}

template<class _Ty> inline
	_Boolarray operator>(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar > valarray
	_VALOP(_Bool, _Right.size(), _Left > _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator>(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray > valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] > _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator<=(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray <= scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] <= _Right);
	}

template<class _Ty> inline
	_Boolarray operator<=(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar <= valarray
	_VALOP(_Bool, _Right.size(), _Left <= _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator<=(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray <= valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] <= _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator>=(const valarray<_Ty>& _Left,
		const _Ty& _Right)
	{	// return valarray >= scalar
	_VALOP(_Bool, _Left.size(), _Left[_Idx] >= _Right);
	}

template<class _Ty> inline
	_Boolarray operator>=(const _Ty& _Left,
		const valarray<_Ty>& _Right)
	{	// return scalar >= valarray
	_VALOP(_Bool, _Right.size(), _Left >= _Right[_Idx]);
	}

template<class _Ty> inline
	_Boolarray operator>=(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// return valarray >= valarray
	_VALOP(_Bool, _Left.size(), _Left[_Idx] >= _Right[_Idx]);
	}

template<class _Ty> inline
	valarray<_Ty> abs(const valarray<_Ty>& _Left)
	{	// apply abs to each element of valarray
	_VALOP(_Ty, _Left.size(), abs(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> acos(const valarray<_Ty>& _Left)
	{	// apply acos to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD acos(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> asin(const valarray<_Ty>& _Left)
	{	// apply asin to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD asin(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> atan(const valarray<_Ty>& _Left)
	{	// apply atan to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD atan(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> atan2(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// apply atan2 to pairs of valarray elements
	_VALOP(_Ty, _Left.size(), _CSTD atan2(_Left[_Idx], _Right[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> atan2(const valarray<_Ty>& _Left, const _Ty& _Right)
	{	// apply atan2 to each valarray element and scalar
	_VALOP(_Ty, _Left.size(), _CSTD atan2(_Left[_Idx], _Right));
	}

template<class _Ty> inline
	valarray<_Ty> atan2(const _Ty& _Left, const valarray<_Ty>& _Right)
	{	// apply atan2 to scalar and each valarray element
	_VALOP(_Ty, _Right.size(), _CSTD atan2(_Left, _Right[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> cos(const valarray<_Ty>& _Left)
	{	// apply cos to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD cos(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> cosh(const valarray<_Ty>& _Left)
	{	// apply cosh to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD cosh(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> exp(const valarray<_Ty>& _Left)
	{	// apply exp to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD exp(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> log(const valarray<_Ty>& _Left)
	{	// apply log to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD log(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> log10(const valarray<_Ty>& _Left)
	{	// apply log10 to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD log10(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> pow(const valarray<_Ty>& _Left,
		const valarray<_Ty>& _Right)
	{	// apply pow to pairs of valarray elements
	_VALOP(_Ty, _Left.size(), _CSTD pow(_Left[_Idx], _Right[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> pow(const valarray<_Ty>& _Left, const _Ty& _Right)
	{	// apply pow to each valarray element and scalar
	_VALOP(_Ty, _Left.size(), _CSTD pow(_Left[_Idx], _Right));
	}

template<class _Ty> inline
	valarray<_Ty> pow(const _Ty& _Left, const valarray<_Ty>& _Right)
	{	// apply pow to scalar and each valarray element
	_VALOP(_Ty, _Right.size(), _CSTD pow(_Left, _Right[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> sin(const valarray<_Ty>& _Left)
	{	// apply sin to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD sin(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> sinh(const valarray<_Ty>& _Left)
	{	// apply sinh to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD sinh(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> sqrt(const valarray<_Ty>& _Left)
	{	// apply sqrt to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD sqrt(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> tan(const valarray<_Ty>& _Left)
	{	// apply tan to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD tan(_Left[_Idx]));
	}

template<class _Ty> inline
	valarray<_Ty> tanh(const valarray<_Ty>& _Left)
	{	// apply tanh to each element of valarray
	_VALOP(_Ty, _Left.size(), _CSTD tanh(_Left[_Idx]));
	}

		// CLASS slice
class slice
	{	// define a slice of a valarray
public:
	slice()
		: _Start(0), _Len(0), _Stride(0)
		{	// construct with all zeros
		}

	slice(size_t _Off, size_t _Count, size_t _Inc)
		: _Start(_Off), _Len(_Count), _Stride(_Inc)
		{	// construct slice from starting offset, length, and stride
		}

	size_t start() const
		{	// return starting offset of slice
		return (_Start);
		}

	size_t size() const
		{	// return number of elements specified by slice
		return (_Len);
		}

	size_t stride() const
		{	// return distance between elements specified by slice
		return (_Stride);
		}

protected:
	size_t _Start;	// the starting offset
	size_t _Len;	// the number of elements
	size_t _Stride;	// the distance between elements
	};

		// MACROS FOR slice_array
#define _SLOP(RHS)	/* apply RHS(_Idx) to slice_array */ \
	size_t _Off = _Start; \
	for (size_t _Idx = 0; _Idx < _Len; ++_Idx, _Off += _Stride) \
		_Myptr[_Off] RHS;

		// TEMPLATE CLASS slice_array
template<class _Ty>
	class slice_array
		: public slice
	{	// define a slice of a valarray
public:
	typedef _Ty value_type;

	void operator=(const valarray<_Ty>& _Right) const
		{	// assign a valarray to a slice
		_SLOP(= _Right[_Idx]);
		}

	void operator=(const _Ty& _Right) const
		{	// assign a scalar to elements of a slice
		_SLOP(= _Right);
		}

	void operator*=(const valarray<_Ty>& _Right) const
		{	// multiply slice by valarray
		_SLOP(*= _Right[_Idx]);
		}

	void operator/=(const valarray<_Ty>& _Right) const
		{	// divide slice by valarray
		_SLOP(/= _Right[_Idx]);
		}

	void operator%=(const valarray<_Ty>& _Right) const
		{	// remainder slice by valarray
		_SLOP(%= _Right[_Idx]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -