cwVectOps.h : Added find() and count().
This commit is contained in:
parent
9bf3485e61
commit
8e1004b2a3
24
cwVectOps.h
24
cwVectOps.h
@ -169,6 +169,30 @@ namespace cw
|
|||||||
|
|
||||||
return v0;
|
return v0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==================================================================================================================
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==================================================================================================================
|
//==================================================================================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user