DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

pos(C++)


pos -- find the leftmost element in an array satisfying a given criterion

Synopsis

   template <class T>
   const T* pos(const T& val,const T* b,const T* e);
   template <class T>
   const T* pos_p(int (*pred)(const T*),
        const T* b,const T* e);
   template <class T>
   const T* pos_r(
        int (*rel)(const T*,const T*),
        const T& val,
        const T* b,
        const T* e
   );

Assumptions

(C) For the plain version, T::operator== defines an equivalence relation on T.

(2) For the relational version, rel defines an equivalence relation on T.

Description

These functions return a pointer to the leftmost element satisfying some criterion. If no such element can be found, they return 0.

   template <class T>
   const T* pos(const T& val,const T* b,const T* e);

Uses equality with val as the criterion, with T::operator== used for the equality test.

   template <class T>
   const T* pos_p(int (*pred)(const T*,const T* b,const T* e);

Uses the predicate pred as the criterion. That is, if p is a pointer into the array, then *p satisfies the criterion if pred(p) is true.

   template <class T>
   const T* pos_r(
       int (*rel)(const T*,const T*),
       const T& val,
       const T* b,
       const T* e
       );

Like pred, except that it uses rel for the equality test.

Complexity

If N is the size of the array, complexity is O(N). At most N equality tests are done.

Notes

Because a Block (see Block(3C++)) can always be used wherever an array is called for, Array Algorithms can also be used with Blocks. In fact, these two components were actually designed to be used together.

References

Array_alg(C++), Block(C++), rt_pos(C++)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005