52 #ifndef __PCL_Utility_h
53 #define __PCL_Utility_h
58 #include <pcl/Diagnostics.h>
89 template <
typename T>
inline constexpr
90 const T&
Min(
const T& a,
const T& b ) noexcept
92 return (b < a) ? b : a;
104 template <
typename T,
class BP>
inline
105 const T&
Min(
const T& a,
const T& b, BP p ) noexcept( noexcept( p ) )
107 return p( b, a ) ? b : a;
118 template <
typename T>
inline constexpr
119 const T&
Max(
const T& a,
const T& b ) noexcept
121 return (a < b) ? b : a;
133 template <
typename T,
class BP>
inline
134 const T&
Max(
const T& a,
const T& b, BP p ) noexcept( noexcept( p ) )
136 return p( a, b ) ? b : a;
150 template <
typename T>
inline constexpr
151 const T&
Median(
const T& a,
const T& b,
const T& c ) noexcept
153 return (a < b) ? ((b < c) ? b : ((a < c) ? c : a)) :
154 ((a < c) ? a : ((b < c) ? c : b));
169 template <
typename T,
class BP>
inline
170 const T&
Median(
const T& a,
const T& b,
const T& c, BP p ) noexcept( noexcept( p ) )
172 return p( a, b ) ? (p( b, c ) ? b : (p( a, c ) ? c : a)) :
173 (p( a, c ) ? a : (p( b, c ) ? c : b));
189 template <
typename T>
inline constexpr
190 const T&
Range(
const T& x,
const T& a,
const T& b ) noexcept
192 PCL_PRECONDITION( a < b )
193 return (x < a) ? a : ((b < x) ? b : x);
209 template <
typename T,
class BP>
inline
210 const T&
Range(
const T& x,
const T& a,
const T& b, BP p ) noexcept( noexcept( p ) )
212 PCL_PRECONDITION( p( a, b ) )
213 return p( x, a ) ? a : (p( b, x ) ? b : x);
223 #define ItemsInArray( a ) (sizeof( a )/sizeof( *a ))
232 template <
typename T>
inline
233 void Swap( T& a, T& b ) noexcept( std::is_nothrow_copy_constructible<T>::value
234 && std::is_nothrow_copy_assignable<T>::value
235 && std::is_nothrow_move_assignable<T>::value )
237 T c( a ); a = b; b = std::move( c );
248 template <
class FI,
class F>
inline
249 void Apply( FI i, FI j, F f ) noexcept( noexcept( f ) )
264 template <
class FI,
class F,
typename T1>
inline
265 void Apply( FI i, FI j, F f, T1 x ) noexcept( noexcept( f ) )
281 template <
class FI,
class F,
class UP>
inline
282 void ApplyIf( FI i, FI j, F f, UP p ) noexcept( noexcept( f ) && noexcept( p ) )
299 template <
class FI,
class F,
class UP,
typename T1>
inline
300 void ApplyIf( FI i, FI j, F f, UP p, T1 x ) noexcept( noexcept( f ) && noexcept( p ) )
315 template <
class FI,
class UP>
inline
316 FI
FirstThat( FI i, FI j, UP p ) noexcept( noexcept( p ) )
318 for ( ; i != j; ++i )
332 template <
class FI,
class UP,
typename T1>
inline
333 FI
FirstThat( FI i, FI j, UP p, T1 x ) noexcept( noexcept( p ) )
335 for ( ; i != j; ++i )
349 template <
class BI,
class UP>
inline
350 BI
LastThat( BI i, BI j, UP p ) noexcept( noexcept( p ) )
352 for ( BI k = j; i != k; )
366 template <
class BI,
class UP,
typename T1>
inline
367 BI
LastThat( BI i, BI j, UP p, T1 x ) noexcept( noexcept( p ) )
369 for ( BI k = j; i != k; )
383 template <
class FI,
typename T>
inline
403 template <
class FI,
typename T,
class BP>
inline
422 template <
class FI,
class UP>
inline
440 template <
class FI>
inline
459 template <
class FI,
class BP>
inline
460 FI
MinItem( FI i, FI j, BP p ) noexcept( noexcept( p ) )
478 template <
class FI>
inline
497 template <
class FI,
class BP>
inline
498 FI
MaxItem( FI i, FI j, BP p ) noexcept( noexcept( p ) )
516 template <
class FI>
inline
538 template <
class FI,
class BP>
inline
545 if ( p( *i, *kmin ) )
547 if ( p( *kmax, *i ) )
560 template <
class FI1,
class FI2>
inline
563 for ( ; i2 != j2 && *i1 == *i2; ++i1, ++i2 ) {}
575 template <
class FI1,
class FI2,
class BP>
inline
578 for ( ; i2 != j2 && p( *i1, *i2 ); ++i1, ++i2 ) {}
591 template <
class FI1,
class FI2>
inline
592 bool Equal( FI1 i1, FI2 i2, FI2 j2 ) noexcept
606 template <
class FI1,
class FI2,
class BP>
inline
607 bool Equal( FI1 i1, FI2 i2, FI2 j2, BP p ) noexcept( noexcept( p ) )
638 template <
class FI1,
class FI2>
inline
639 int Compare( FI1 i1, FI1 j1, FI2 i2, FI2 j2 ) noexcept
641 for ( ; ; ++i1, ++i2 )
644 return (i2 == j2) ? 0 : -1;
682 template <
class FI1,
class FI2,
class BP>
inline
683 int Compare( FI1 i1, FI1 j1, FI2 i2, FI2 j2, BP p ) noexcept( noexcept( p ) )
685 for ( ; ; ++i1, ++i2 )
688 return (i2 == j2) ? 0 : -1;
Generic association of two objects.
Association< T1, T2 > Associate(const T1 &x1, const T2 &x2)
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
double Median(const T *__restrict__ i, const T *__restrict__ j)
size_type CountIf(FI i, FI j, UP p) noexcept(noexcept(p))
void ApplyIf(FI i, FI j, F f, UP p) noexcept(noexcept(f) &&noexcept(p))
constexpr const T & Min(const T &a, const T &b) noexcept
BI LastThat(BI i, BI j, UP p) noexcept(noexcept(p))
size_type Count(FI i, FI j, const T &v) noexcept
FI MinItem(FI i, FI j) noexcept
Association< FI1, FI2 > FindNotEqual(FI1 i1, FI2 i2, FI2 j2) noexcept
bool Equal(FI1 i1, FI2 i2, FI2 j2) noexcept
void FindExtremeItems(FI &kmin, FI &kmax, FI i, FI j) noexcept
int Compare(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept
FI MaxItem(FI i, FI j) noexcept
void Apply(FI i, FI j, F f) noexcept(noexcept(f))
FI FirstThat(FI i, FI j, UP p) noexcept(noexcept(p))