rt_pos(3C++)


rt_pos -- find the rightmost element in an array satisfying a given criterion

Synopsis

   template <class T>
   const T* rt_pos(
        const T& val,
        const T* b,
        const T* e
   );
   template <class T>
   const T* rt_pos_p(
        int (*pred)(const T*),
        const T* b,
        const T* e
   );
   template <class T>
   const T* rt_pos_r(
        int (*rel)(const T*,const T*),
        const T& val,
        const T* b,
        const T* e
   );

Assumptions

(1) 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 rightmost element satisfying some criterion. If no such element can be found, they return 0.

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

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

   template <class T>
   const T* rt_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* rt_pos_r(
       int (*rel)(const T*, const T),
       const T& val,
       const T* b,
       const T* e
       );

Like rt_pos except that rel is used for the equality test.

Complexity

If N is the size of the array, then 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(3C++), Block(3C++), pos(3C++)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004