cwVectOps.h : Added find() and count().
This commit is contained in:
parent
9bf3485e61
commit
8e1004b2a3
24
cwVectOps.h
24
cwVectOps.h
@ -171,6 +171,30 @@ namespace cw
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==================================================================================================================
|
||||||
|
// find, count
|
||||||
|
//
|
||||||
|
|
||||||
|
template< typename T0, typename T1 >
|
||||||
|
unsigned find( const T0* v, unsigned n, const T1& m )
|
||||||
|
{
|
||||||
|
for(unsigned i=0; i<n; ++i)
|
||||||
|
if( v[i] == m )
|
||||||
|
return i;
|
||||||
|
return kInvalidIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T0, typename T1 >
|
||||||
|
unsigned count( const T0* v, unsigned n, const T1& m )
|
||||||
|
{
|
||||||
|
unsigned cnt = 0;
|
||||||
|
for(unsigned i=0; i<n; ++i)
|
||||||
|
if( v[i] == m )
|
||||||
|
cnt += 1;
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==================================================================================================================
|
//==================================================================================================================
|
||||||
// absolute value
|
// absolute value
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user