All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Algorithm.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_ALGORITHM_H_
36 #define _BLAZE_UTIL_ALGORITHM_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/util/Types.h>
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // POLYMORPHIC COUNT
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
66 template< typename D // Dynamic type of the objects
67  , typename S > // Static type of the objects
68 inline size_t polymorphicCount( S *const * first, S *const * last )
69 {
71 
72  size_t count( 0 );
73  for( S *const * it=first; it!=last; ++it )
74  if( dynamic_cast<D*>( *it ) ) ++count;
75  return count;
76 }
77 //*************************************************************************************************
78 
79 
80 
81 
82 //=================================================================================================
83 //
84 // POLYMORPHIC FIND
85 //
86 //=================================================================================================
87 
88 //*************************************************************************************************
99 template< typename D // Dynamic type of the objects
100  , typename S > // Static type of the objects
101 inline S *const * polymorphicFind( S *const * first, S *const * last )
102 {
104 
105  while( first != last && !dynamic_cast<D*>( *first ) ) ++first;
106  return first;
107 }
108 //*************************************************************************************************
109 
110 } // namespace blaze
111 
112 #endif
size_t polymorphicCount(S *const *first, S *const *last)
Counts the pointer to objects with dynamic type D.
Definition: Algorithm.h:68
#define BLAZE_CONSTRAINT_MUST_BE_STRICTLY_DERIVED_FROM(D, B)
Constraint on the inheritance relationship of a data type.In case D is not derived from B...
Definition: DerivedFrom.h:157
S *const * polymorphicFind(S *const *first, S *const *last)
Finds the next pointer to an object with dynamic type D.
Definition: Algorithm.h:101
Constraint on the inheritance relationship of a data type.
Header file for basic type definitions.