From 0ed446321696b495ad2c9ceb5c3f894f840bfc4a Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 21 Jun 2018 17:13:57 +0200
Subject: [PATCH] document clone and compare files in alib2std

---
 alib2std/src/extensions/clone.hpp   |  34 +++
 alib2std/src/extensions/compare.hpp | 350 +++++++++++++++++++++++-----
 2 files changed, 332 insertions(+), 52 deletions(-)

diff --git a/alib2std/src/extensions/clone.hpp b/alib2std/src/extensions/clone.hpp
index c5d5af8d2d..3e11b93e1b 100644
--- a/alib2std/src/extensions/clone.hpp
+++ b/alib2std/src/extensions/clone.hpp
@@ -1,6 +1,22 @@
 /*
  * clone.hpp
  *
+ * This file is part of Algorithms library toolkit.
+ * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
+
+ * Algorithms library toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * Algorithms library toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with Algorithms library toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ *
  * Created on: Apr 1, 2013
  * Author: Jan Travnicek
  */
@@ -12,11 +28,29 @@
 
 namespace ext {
 
+/**
+ * Wrapper around clone by means of using copy constructor.
+ *
+ * \param tmp universal reference to a value to be cloned.
+ *
+ * \tparam T the type of cloned value
+ *
+ * \return the cloned value dynamically allocated
+ */
 template < class T, typename std::enable_if < ! ext::has_clone < T >::value >::type * = nullptr >
 auto clone ( T && tmp ) {
 	return new typename std::decay < T >::type ( std::forward < T > ( tmp ) );
 }
 
+/**
+ * Wrapper around clone by means of using clone method.
+ *
+ * \param tmp universal reference to a value to be cloned.
+ *
+ * \tparam T the type of cloned value
+ *
+ * \return the cloned value dynamically allocated
+ */
 template < class T, typename std::enable_if < ext::has_clone < T >::value >::type * = nullptr >
 auto clone ( T && tmp ) {
 	return std::forward < T > ( tmp ).clone ( );
diff --git a/alib2std/src/extensions/compare.hpp b/alib2std/src/extensions/compare.hpp
index e5096ff5d2..d9695ec6b8 100644
--- a/alib2std/src/extensions/compare.hpp
+++ b/alib2std/src/extensions/compare.hpp
@@ -1,6 +1,22 @@
 /*
  * compare.hpp
  *
+ * This file is part of Algorithms library toolkit.
+ * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
+
+ * Algorithms library toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+
+ * Algorithms library toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with Algorithms library toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ *
  * Created on: Apr 1, 2013
  * Author: Jan Travnicek
  */
@@ -12,68 +28,182 @@
 
 namespace ext {
 
+/**
+ * Predefinition of the compare structure implementing the three-way comparison
+ *
+ * \tparam T the type of compared value
+ * \tparam Enable the place for enable_if construct if needed
+ */
 template < typename T, typename Enable = void >
 struct compare;
 
-template<>
-struct compare<bool> {
-	int operator()(bool first, bool second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for bools
+ */
+template < >
+struct compare < bool > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( bool first, bool second ) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<unsigned char> {
-	int operator()(unsigned char first, unsigned char second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for unsigned chars
+ */
+template < >
+struct compare < unsigned char > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( unsigned char first, unsigned char second ) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<signed char> {
-	int operator()(signed char first, signed char second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for signed chars
+ */
+template < >
+struct compare < signed char > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( signed char first, signed char second ) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<char> {
-	int operator()(char first, char second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for chars
+ */
+template < >
+struct compare < char > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( char first, char second ) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<unsigned short> {
-	int operator()(unsigned short first, unsigned short second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for unsigned shorts
+ */
+template < >
+struct compare < unsigned short > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( unsigned short first, unsigned short second ) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<signed short> {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for signed shorts
+ */
+template < >
+struct compare < signed short > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
 	int operator()(signed short first, signed short second) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<unsigned int> {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for unsigned ints
+ */
+template < >
+struct compare < unsigned int > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
 	int operator()(unsigned int first, unsigned int second) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<signed int> {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for signed ints
+ */
+template < >
+struct compare < signed int > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
 	int operator()(signed int first, signed int second) const {
 		return first - second;
 	}
 };
 
-template<>
-struct compare<signed long> {
-	int operator()(signed long first, signed long second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for unsigned longs
+ */
+template < >
+struct compare < unsigned long > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( unsigned long first, unsigned long second ) const {
 		if ( first < second )
 			return -1;
 		else if ( first > second )
@@ -83,9 +213,21 @@ struct compare<signed long> {
 	}
 };
 
-template<>
-struct compare<unsigned long> {
-	int operator()(unsigned long first, unsigned long second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for signed longs
+ */
+template < >
+struct compare < signed long > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( signed long first, signed long second ) const {
 		if ( first < second )
 			return -1;
 		else if ( first > second )
@@ -95,9 +237,21 @@ struct compare<unsigned long> {
 	}
 };
 
-template<>
-struct compare<signed long long> {
-	int operator()(signed long long first, signed long long second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for unsigned long longs
+ */
+template < >
+struct compare < unsigned long long > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( unsigned long long first, unsigned long long second ) const {
 		if ( first < second )
 			return -1;
 		else if ( first > second )
@@ -107,9 +261,21 @@ struct compare<signed long long> {
 	}
 };
 
-template<>
-struct compare<unsigned long long> {
-	int operator()(unsigned long long first, unsigned long long second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for signed long longs
+ */
+template < >
+struct compare < signed long long > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( signed long long first, signed long long second ) const {
 		if ( first < second )
 			return -1;
 		else if ( first > second )
@@ -119,9 +285,21 @@ struct compare<unsigned long long> {
 	}
 };
 
-template<>
-struct compare<float> {
-	int operator()(float first, float second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for floats
+ */
+template < >
+struct compare < float > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( float first, float second ) const {
 		if ( first < second )
 			return -1;
 		else if ( first > second )
@@ -131,9 +309,21 @@ struct compare<float> {
 	}
 };
 
-template<>
-struct compare<double> {
-	int operator()(double first, double second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for doubles
+ */
+template < >
+struct compare < double > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( double first, double second ) const {
 		if ( first < second )
 			return -1;
 		else if ( first > second )
@@ -143,9 +333,21 @@ struct compare<double> {
 	}
 };
 
-template<>
-struct compare<long double> {
-	int operator()(long double first, long double second) const {
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for long doubles
+ */
+template < >
+struct compare < long double > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( long double first, long double second ) const {
 		if ( first < second )
 			return -1;
 		else if ( first > second )
@@ -155,19 +357,63 @@ struct compare<long double> {
 	}
 };
 
-template<class T>
-struct compare<T*> {
-	int operator()( T * const & first, T * const & second) const {
-		static compare<typename std::decay < T >::type > comp;
-		return comp(*first, *second);
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for pointers
+ */
+template < class T >
+struct compare < T * > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( T * const first, T * const second ) const {
+		static compare < typename std::decay < T >::type > comp;
+		return comp ( * first, * second );
 	}
 };
 
-template<class T>
-struct compare<T&> {
-	int operator()( const T & first, const T & second) const {
-		static compare<typename std::decay < T >::type > comp;
-		return comp(first, second);
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for lvalue references
+ */
+template < class T >
+struct compare < T & > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( const T & first, const T & second ) const {
+		static compare < typename std::decay < T >::type > comp;
+		return comp ( first, second );
+	}
+};
+
+/**
+ * Specialisation of the compare structure implementing the three-way comparison for rvalue references
+ */
+template < class T >
+struct compare < T && > {
+
+	/**
+	 * Implementation of the three-way comparison
+	 *
+	 * \param first the left operand of the comparison
+	 * \param second the right operand of the comparison
+	 *
+	 * \return negative value of left < right, positive value if left > right, zero if left == right
+	 */
+	int operator ( ) ( const T & first, const T & second ) const {
+		static compare < typename std::decay < T >::type > comp;
+		return comp ( first, second );
 	}
 };
 
-- 
GitLab