diff --git a/alib2std/src/extensions/array.hpp b/alib2std/src/extensions/array.hpp index fb1152fc629c7b0f30ec159a1ac78ab01234693f..e8af083731cdebcaf35d5c591cadf9274c064f1f 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 41083254da820079260a03b29f46597e45939fb6..5ccd53e23372f23366818af7e5ac93351005486e 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 47eb9efca6e87fffee8380065dc74af2047d2f69..6e6f3daae9af79bc53d69707c478f35af3554a90 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 4c9d4b7fd82cef0a5f814452600b2ca796548f1e..5a06c33f4bf87c7605b3659b73f565808d0afb14 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 c4e006566ad8c11f373c9de324cf16142f117643..2c81a6971ff94acdf1e72ec2ff062ab5e5cf81f2 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 2adad7e1d1721bd4577b84f4f0497a3bf3f42b59..91b0bcaaae5c2ee28f6688549f74f2278c4917e3 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 e8326f3a489088e06c91d7c4225034284ea92547..8f6840beadda370bf0cdaa8b6cfb4c10b847685c 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 93f7cc4c5ed55c5ad39d6aef5d773699451bb536..a6075e384ed4c989b06dfd6c0427ea9ee11ca0d8 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 9d0144e471980fec595f61eed2fdb3d1eb9d8fbc..a43fca6c58963d4bbedb60fb8a2924668d0c7250 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;