From a1f29ecf67376df720190d9b592768e503801536 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 9 Jul 2018 14:32:04 +0200 Subject: [PATCH] continue documenting alib2std --- alib2std/src/extensions/array.hpp | 4 +- alib2std/src/extensions/bitset.hpp | 4 +- alib2std/src/extensions/deque.hpp | 4 +- alib2std/src/extensions/forward_list.hpp | 4 +- alib2std/src/extensions/forward_tree.hpp | 11 +++- alib2std/src/extensions/linear_set.hpp | 4 +- alib2std/src/extensions/list.hpp | 4 +- alib2std/src/extensions/map.hpp | 4 +- alib2std/src/extensions/pair.hpp | 78 ++++++++++++++++++++++++ 9 files changed, 102 insertions(+), 15 deletions(-) diff --git a/alib2std/src/extensions/array.hpp b/alib2std/src/extensions/array.hpp index fb1152fc62..e8af083731 100644 --- a/alib2std/src/extensions/array.hpp +++ b/alib2std/src/extensions/array.hpp @@ -180,7 +180,7 @@ std::ostream& operator<<(std::ostream& out, const ext::array < T, N > & array) { } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam T the type of values inside the array * \tparam N the size of the array @@ -189,7 +189,7 @@ template< class T, std::size_t N > struct compare < ext::array < T, N > > { /** - * Implementation of the three-way comparison + * Implementation of the three-way comparison. * * \param first the left operand of the comparison * \param second the right operand of the comparison diff --git a/alib2std/src/extensions/bitset.hpp b/alib2std/src/extensions/bitset.hpp index 41083254da..5ccd53e233 100644 --- a/alib2std/src/extensions/bitset.hpp +++ b/alib2std/src/extensions/bitset.hpp @@ -105,7 +105,7 @@ std::ostream & operator << ( std::ostream & out, const ext::bitset < N > & bitse } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam N the size of the bitset */ @@ -113,7 +113,7 @@ template < size_t N > struct compare < ext::bitset < N > > { /** - * Implementation of the three-way comparison + * Implementation of the three-way comparison. * * \param first the left operand of the comparison * \param second the right operand of the comparison diff --git a/alib2std/src/extensions/deque.hpp b/alib2std/src/extensions/deque.hpp index 47eb9efca6..6e6f3daae9 100644 --- a/alib2std/src/extensions/deque.hpp +++ b/alib2std/src/extensions/deque.hpp @@ -172,7 +172,7 @@ std::ostream & operator <<( std::ostream & out, const ext::deque < T, Ts ... > & } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam T the type of values inside the deque * \tparam Ts ... remaining unimportant template parameters of the deque @@ -181,7 +181,7 @@ template < class T, class ... Ts > struct compare < ext::deque < T, Ts ... > > { /** - * Implementation of the three-way comparison + * Implementation of the three-way comparison. * * \param first the left operand of the comparison * \param second the right operand of the comparison diff --git a/alib2std/src/extensions/forward_list.hpp b/alib2std/src/extensions/forward_list.hpp index 4c9d4b7fd8..5a06c33f4b 100644 --- a/alib2std/src/extensions/forward_list.hpp +++ b/alib2std/src/extensions/forward_list.hpp @@ -110,7 +110,7 @@ std::ostream& operator<<(std::ostream& out, const ext::forward_list<T, Ts ... >& } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam T the type of values inside the forward_list * \tparam Ts ... remaining unimportant template parameters of the forward_list @@ -119,7 +119,7 @@ template<class T, class ... Ts > struct compare<ext::forward_list<T, Ts ... >> { /** - * Implementation of the three-way comparison + * Implementation of the three-way comparison. * * \param first the left operand of the comparison * \param second the right operand of the comparison diff --git a/alib2std/src/extensions/forward_tree.hpp b/alib2std/src/extensions/forward_tree.hpp index c4e006566a..2c81a6971f 100644 --- a/alib2std/src/extensions/forward_tree.hpp +++ b/alib2std/src/extensions/forward_tree.hpp @@ -1210,12 +1210,21 @@ std::ostream & operator <<( std::ostream & out, const forward_tree < T > & t ) { } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam T the type of values inside the forward_tree */ template < class T > struct compare < ext::forward_tree < 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 ext::forward_tree < T > & first, const ext::forward_tree < T > & second ) const { return first.compare ( second ); } diff --git a/alib2std/src/extensions/linear_set.hpp b/alib2std/src/extensions/linear_set.hpp index 2adad7e1d1..91b0bcaaae 100644 --- a/alib2std/src/extensions/linear_set.hpp +++ b/alib2std/src/extensions/linear_set.hpp @@ -841,7 +841,7 @@ std::ostream& operator<<(std::ostream& out, const ext::linear_set<T, Ts ...>& va } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam T the type of values inside the set * \tparam Ts ... remaining unimportant template parameters of the set @@ -850,7 +850,7 @@ template<class T, class ... Ts> struct compare<ext::linear_set<T, Ts ...>> { /** - * Implementation of the three-way comparison + * Implementation of the three-way comparison. * * \param first the left operand of the comparison * \param second the right operand of the comparison diff --git a/alib2std/src/extensions/list.hpp b/alib2std/src/extensions/list.hpp index e8326f3a48..8f6840bead 100644 --- a/alib2std/src/extensions/list.hpp +++ b/alib2std/src/extensions/list.hpp @@ -170,7 +170,7 @@ std::ostream& operator<<(std::ostream& out, const ext::list<T, Ts ... >& list) { } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam T the type of values inside the list * \tparam Ts ... remaining unimportant template parameters of the list @@ -179,7 +179,7 @@ template < class T, class ... Ts > struct compare < ext::list < T, Ts ... > > { /** - * Implementation of the three-way comparison + * Implementation of the three-way comparison. * * \param first the left operand of the comparison * \param second the right operand of the comparison diff --git a/alib2std/src/extensions/map.hpp b/alib2std/src/extensions/map.hpp index 93f7cc4c5e..a6075e384e 100644 --- a/alib2std/src/extensions/map.hpp +++ b/alib2std/src/extensions/map.hpp @@ -265,7 +265,7 @@ std::ostream& operator<<(std::ostream& out, const ext::map<T, R, Ts ... >& map) } /** - * Specialisation of the compare structure implementing the three-way comparison + * Specialisation of the compare structure implementing the three-way comparison. * * \tparam T the type of keys inside the map * \tparam R the type of values inside the map @@ -275,7 +275,7 @@ template < class T, class R, class ... Ts > struct compare < ext::map < T, R, Ts ... > > { /** - * Implementation of the three-way comparison + * Implementation of the three-way comparison. * * \param first the left operand of the comparison * \param second the right operand of the comparison diff --git a/alib2std/src/extensions/pair.hpp b/alib2std/src/extensions/pair.hpp index 9d0144e471..a43fca6c58 100644 --- a/alib2std/src/extensions/pair.hpp +++ b/alib2std/src/extensions/pair.hpp @@ -1,6 +1,22 @@ /* * pair.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 */ @@ -17,18 +33,46 @@ namespace ext { +/** + * Class extending the pair class from the standard library. Original reason is to allow printing of the pair with overloaded operator <<. + * + * The class mimics the behavior of the pair from the standatd library. + * + * \tparam T the type of the first value inside the pair + * \tparam R the type of the second value inside the pair + */ template < class T, class R > class pair : public std::pair < T, R > { public: + /** + * Inherit constructors of the standard pair + */ using std::pair < T, R >::pair; + + /** + * Inherit operator = of the standard pair + */ using std::pair < T, R >::operator =; #ifndef __clang__ + + /** + * Default constructor needed by g++ since it is not inherited + */ pair ( const pair & other ) = default; + /** + * Copy constructor needed by g++ since it is not inherited + */ pair ( pair && other ) = default; + /** + * Copy operator = needed by g++ since it is not inherited + */ pair & operator = ( pair && other ) = default; + /** + * Move operator = needed by g++ since it is not inherited + */ pair & operator = ( const pair & other ) = default; #endif }; @@ -41,14 +85,40 @@ constexpr ext::pair < typename std::__decay_and_strip < _T1 >::__type, typename return __pair_type ( std::forward < _T1 > ( __x ), std::forward < _T2 > ( __y ) ); } +/** + * Operator to print the pair to the output stream. + * + * \param out the output stream + * \param pair the pair to print + * + * \tparam T the type of the first value inside the pair + * \tparam R the type of the second value inside the pair + * + * \return the output stream from the \p out + */ template< class T, class R > std::ostream& operator<<(std::ostream& out, const ext::pair<T, R>& pair) { out << "(" << pair.first << ", " << pair.second << ")"; return out; } +/** + * Specialisation of the compare structure implementing the three-way comparison. + * + * \tparam T the type of the first value inside the pair + * \tparam R the type of the second value inside the pair + */ template < class T, class R > struct compare < ext::pair < T, R > > { + + /** + * 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 ext::pair < T, R > & first, const ext::pair < T, R > & second ) const { static compare < typename std::decay < T >::type > compT; static compare < typename std::decay < R >::type > compR; @@ -59,6 +129,14 @@ struct compare < ext::pair < T, R > > { } }; +/** + * Overload of to_string function. + * + * \param value the pair to be converted to string + * + * \tparam T the type of the first value inside the pair + * \tparam R the type of the second value inside the pair + */ template < class T, class R > std::string to_string ( const ext::pair < T, R > & value ) { std::stringstream ss; -- GitLab