Merge pull request #2146 from Azaezel/specializationShenanigans

changes find, swap, for_each, and delete_pointer from global to t3d namespace
This commit is contained in:
Areloch 2018-04-17 03:02:03 -05:00 committed by GitHub
commit bc1b506205
20 changed files with 70 additions and 69 deletions

View file

@ -23,40 +23,41 @@
#ifndef _TALGORITHM_H_
#define _TALGORITHM_H_
/// Finds the first matching value within the container
/// returning the the element or last if its not found.
template <class Iterator, class Value>
Iterator find(Iterator first, Iterator last, Value value)
namespace T3D
{
while (first != last && *first != value)
++first;
return first;
/// Finds the first matching value within the container
/// returning the the element or last if its not found.
template <class Iterator, class Value>
Iterator find(Iterator first, Iterator last, Value value)
{
while (first != last && *first != value)
++first;
return first;
}
/// Exchanges the values of the two elements.
template <typename T>
inline void swap(T &left, T &right)
{
T temp = right;
right = left;
left = temp;
}
/// Steps thru the elements of an array calling detete for each.
template <class Iterator, class Functor>
void for_each(Iterator first, Iterator last, Functor func)
{
for (; first != last; first++)
func(*first);
}
/// Functor for deleting a pointer.
/// @see for_each
struct delete_pointer
{
template <typename T>
void operator()(T *ptr) { delete ptr; }
};
}
/// Exchanges the values of the two elements.
template <typename T>
inline void swap( T &left, T &right )
{
T temp = right;
right = left;
left = temp;
}
/// Steps thru the elements of an array calling detete for each.
template <class Iterator, class Functor>
void for_each( Iterator first, Iterator last, Functor func )
{
for ( ; first != last; first++ )
func( *first );
}
/// Functor for deleting a pointer.
/// @see for_each
struct delete_pointer
{
template <typename T>
void operator()(T *ptr){ delete ptr;}
};
#endif //_TALGORITHM_H_