summaryrefslogtreecommitdiffstats
path: root/src/include/algorithm
diff options
context:
space:
mode:
authordgilbert <dgilbert@us.ibm.com>2011-05-09 12:28:02 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2011-05-18 10:41:46 -0500
commit358def6287d9f11e2a80e6e15557d45ff50ec13a (patch)
treebf684616ace7d6331bcf87f32398109a10b5dbfa /src/include/algorithm
parent5f28dffa51ef4fe402e1e8609fd8afa44e834db6 (diff)
downloadtalos-hostboot-358def6287d9f11e2a80e6e15557d45ff50ec13a.tar.gz
talos-hostboot-358def6287d9f11e2a80e6e15557d45ff50ec13a.zip
Initial STL code delivery with code review changes.
Change-Id: Ib4226e1351acce15cacbe643eb2fb4f0dfb56855 Reviewed-on: http://gfwr801.rchland.ibm.com:8080/gerrit/68 Tested-by: Jenkins Server Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/include/algorithm')
-rw-r--r--src/include/algorithm132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/include/algorithm b/src/include/algorithm
new file mode 100644
index 000000000..9bf0aa006
--- /dev/null
+++ b/src/include/algorithm
@@ -0,0 +1,132 @@
+#ifndef ALGORITHM
+#define ALGORITHM
+
+#ifdef __cplusplus
+namespace std
+{
+ /**
+ * Copy a range of elements
+ * @param[in] first InputIterator to the initial position in the source sequence.
+ * @param[in] last InputIterator to last position + 1 in the source sequence.
+ * @param[in] result OutputIterator to initial position in the destination sequence.
+ * @return an iterator to the last element in the destination range
+ * @note If both ranges overlap in such a way that result points to an elmenent in the source
+ * range then fuction copy_backward should be used.
+ */
+ template <class InputIterator, class OutputIterator>
+ inline OutputIterator
+ copy (InputIterator first, InputIterator last, OutputIterator result )
+ {
+ while(first!=last)
+ {
+ *result = *first;
+ ++result;
+ ++first;
+ }
+ return result;
+ }
+
+ /**
+ * Copy a range of elements backwards
+ * @param[in] first Bidirectional iterator to the initial source position
+ * @param[in] last Bidirectional iterator to the final source position + 1
+ * @param[in] result Bidirectional iterator to end of the destination sequence + 1.
+ * @return an iterator to the first element in the destination sequence.
+ * @note If both ranges overlap in such a way that result points to an element in the source
+ * range, the function copy should be used instead.
+ */
+ template <class BidirectionalIterator1, class BidirectionalIterator2>
+ inline BidirectionalIterator2
+ copy_backward ( BidirectionalIterator1 first,
+ BidirectionalIterator1 last,
+ BidirectionalIterator2 result )
+ {
+ while(last!=first)
+ {
+ --result;
+ --last;
+ *result = *last;
+ }
+ return result;
+ }
+
+ /**
+ * Exchange values of two objects
+ * @param[in] a reference to an object to be swaped with b
+ * @param[in] b reference to an object to be swaped with a
+ * @note this function may not be an efficient way to swap large objects.
+ */
+ template <class T>
+ inline void
+ swap(T& a, T&b )
+ {
+ T c(a);
+ a=b;
+ b=c;
+ }
+
+ /**
+ * Fill a range with value
+ * @param[in] first ForwardIterator to the first position in the source range.
+ * @param[in] last ForwardIterator to the last position +1 in the source range.
+ * @param[in] value reference to the object used to fill the sequence.
+ */
+ template < class ForwardIterator, class T >
+ inline void
+ fill (ForwardIterator first, ForwardIterator last, const T& value )
+ {
+ while (first != last)
+ {
+ *first = value;
+ ++first;
+ }
+ }
+
+ /**
+ * Fill a sequence with value
+ * @param[in] first OutputIterator to the first position in the sequence.
+ * @param[in] n number of elements in the sequence
+ * @param[in] value reference to the value used to fill the sequence.
+ */
+ template < class OutputIterator, class Size, class T >
+ inline void
+ fill_n( OutputIterator first, Size n, const T& value )
+ {
+ for(; n>0; --n)
+ {
+ *first = value;
+ ++first;
+ }
+ }
+
+ /**
+ * Return the lesser of two arguments
+ * @param[in] a object reference
+ * @param[in] b object reference
+ * @return reference to te lesser object
+ */
+ template <class T>
+ inline const T&
+ min(const T& a, const T& b)
+ {
+ if( b < a) return b;
+ return a;
+ }
+
+ /**
+ * Return the greater of two arguments
+ * @param[in] a object reference
+ * @param[in] b object reference
+ * @return reference to te greater object
+ */
+ template <class T>
+ inline const T&
+ max(const T& a, const T& b)
+ {
+ if(a < b) return b;
+ return a;
+ }
+};
+#endif
+
+#endif
OpenPOWER on IntegriCloud