40 lines
695 B
C
40 lines
695 B
C
|
#ifndef HGL_Primary_Mathematics_INCLUDE
|
|||
|
#define HGL_Primary_Mathematics_INCLUDE
|
|||
|
namespace hgl
|
|||
|
{
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD>
|
|||
|
*/
|
|||
|
template<typename T>
|
|||
|
const T sum(const T *data,const int count)
|
|||
|
{
|
|||
|
T result=0;
|
|||
|
|
|||
|
for(int i=0;i<count;i++)
|
|||
|
{
|
|||
|
result+=*data;
|
|||
|
++data;
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD>
|
|||
|
*/
|
|||
|
template<typename R,typename T>
|
|||
|
const R sum(const T *data,const int count)
|
|||
|
{
|
|||
|
R result=0;
|
|||
|
|
|||
|
for(int i=0;i<count;i++)
|
|||
|
{
|
|||
|
result+=*data;
|
|||
|
++data;
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
}//namespace hgl
|
|||
|
#endif//HGL_Primary_Mathematics_INCLUDE
|