Skip to content
Snippets Groups Projects
Commit a1f29ecf authored by Jan Trávníček's avatar Jan Trávníček
Browse files

continue documenting alib2std

parent 36e90981
No related branches found
No related tags found
No related merge requests found
...@@ -180,7 +180,7 @@ std::ostream& operator<<(std::ostream& out, const ext::array < T, N > & array) { ...@@ -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 T the type of values inside the array
* \tparam N the size of the array * \tparam N the size of the array
...@@ -189,7 +189,7 @@ template< class T, std::size_t N > ...@@ -189,7 +189,7 @@ template< class T, std::size_t N >
struct compare < ext::array < 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 first the left operand of the comparison
* \param second the right operand of the comparison * \param second the right operand of the comparison
......
...@@ -105,7 +105,7 @@ std::ostream & operator << ( std::ostream & out, const ext::bitset < N > & bitse ...@@ -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 * \tparam N the size of the bitset
*/ */
...@@ -113,7 +113,7 @@ template < size_t N > ...@@ -113,7 +113,7 @@ template < size_t N >
struct compare < ext::bitset < 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 first the left operand of the comparison
* \param second the right operand of the comparison * \param second the right operand of the comparison
......
...@@ -172,7 +172,7 @@ std::ostream & operator <<( std::ostream & out, const ext::deque < T, Ts ... > & ...@@ -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 T the type of values inside the deque
* \tparam Ts ... remaining unimportant template parameters of the deque * \tparam Ts ... remaining unimportant template parameters of the deque
...@@ -181,7 +181,7 @@ template < class T, class ... Ts > ...@@ -181,7 +181,7 @@ template < class T, class ... Ts >
struct compare < ext::deque < T, 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 first the left operand of the comparison
* \param second the right operand of the comparison * \param second the right operand of the comparison
......
...@@ -110,7 +110,7 @@ std::ostream& operator<<(std::ostream& out, const ext::forward_list<T, Ts ... >& ...@@ -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 T the type of values inside the forward_list
* \tparam Ts ... remaining unimportant template parameters of the forward_list * \tparam Ts ... remaining unimportant template parameters of the forward_list
...@@ -119,7 +119,7 @@ template<class T, class ... Ts > ...@@ -119,7 +119,7 @@ template<class T, class ... Ts >
struct compare<ext::forward_list<T, 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 first the left operand of the comparison
* \param second the right operand of the comparison * \param second the right operand of the comparison
......
...@@ -1210,12 +1210,21 @@ std::ostream & operator <<( std::ostream & out, const forward_tree < T > & t ) { ...@@ -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 * \tparam T the type of values inside the forward_tree
*/ */
template < class T > template < class T >
struct compare < ext::forward_tree < 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 { int operator ()( const ext::forward_tree < T > & first, const ext::forward_tree < T > & second ) const {
return first.compare ( second ); return first.compare ( second );
} }
......
...@@ -841,7 +841,7 @@ std::ostream& operator<<(std::ostream& out, const ext::linear_set<T, Ts ...>& va ...@@ -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 T the type of values inside the set
* \tparam Ts ... remaining unimportant template parameters of the set * \tparam Ts ... remaining unimportant template parameters of the set
...@@ -850,7 +850,7 @@ template<class T, class ... Ts> ...@@ -850,7 +850,7 @@ template<class T, class ... Ts>
struct compare<ext::linear_set<T, 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 first the left operand of the comparison
* \param second the right operand of the comparison * \param second the right operand of the comparison
......
...@@ -170,7 +170,7 @@ std::ostream& operator<<(std::ostream& out, const ext::list<T, Ts ... >& list) { ...@@ -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 T the type of values inside the list
* \tparam Ts ... remaining unimportant template parameters of the list * \tparam Ts ... remaining unimportant template parameters of the list
...@@ -179,7 +179,7 @@ template < class T, class ... Ts > ...@@ -179,7 +179,7 @@ template < class T, class ... Ts >
struct compare < ext::list < T, 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 first the left operand of the comparison
* \param second the right operand of the comparison * \param second the right operand of the comparison
......
...@@ -265,7 +265,7 @@ std::ostream& operator<<(std::ostream& out, const ext::map<T, R, Ts ... >& map) ...@@ -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 T the type of keys inside the map
* \tparam R the type of values inside the map * \tparam R the type of values inside the map
...@@ -275,7 +275,7 @@ template < class T, class R, class ... Ts > ...@@ -275,7 +275,7 @@ template < class T, class R, class ... Ts >
struct compare < ext::map < T, R, 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 first the left operand of the comparison
* \param second the right operand of the comparison * \param second the right operand of the comparison
......
/* /*
* pair.hpp * 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 * Created on: Apr 1, 2013
* Author: Jan Travnicek * Author: Jan Travnicek
*/ */
...@@ -17,18 +33,46 @@ ...@@ -17,18 +33,46 @@
   
namespace ext { 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 > template < class T, class R >
class pair : public std::pair < T, R > { class pair : public std::pair < T, R > {
public: public:
/**
* Inherit constructors of the standard pair
*/
using std::pair < T, R >::pair; using std::pair < T, R >::pair;
/**
* Inherit operator = of the standard pair
*/
using std::pair < T, R >::operator =; using std::pair < T, R >::operator =;
#ifndef __clang__ #ifndef __clang__
/**
* Default constructor needed by g++ since it is not inherited
*/
pair ( const pair & other ) = default; pair ( const pair & other ) = default;
   
/**
* Copy constructor needed by g++ since it is not inherited
*/
pair ( pair && other ) = default; pair ( pair && other ) = default;
   
/**
* Copy operator = needed by g++ since it is not inherited
*/
pair & operator = ( pair && other ) = default; pair & operator = ( pair && other ) = default;
   
/**
* Move operator = needed by g++ since it is not inherited
*/
pair & operator = ( const pair & other ) = default; pair & operator = ( const pair & other ) = default;
#endif #endif
}; };
...@@ -41,14 +85,40 @@ constexpr ext::pair < typename std::__decay_and_strip < _T1 >::__type, typename ...@@ -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 ) ); 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 > template< class T, class R >
std::ostream& operator<<(std::ostream& out, const ext::pair<T, R>& pair) { std::ostream& operator<<(std::ostream& out, const ext::pair<T, R>& pair) {
out << "(" << pair.first << ", " << pair.second << ")"; out << "(" << pair.first << ", " << pair.second << ")";
return out; 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 > template < class T, class R >
struct compare < ext::pair < T, 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 { 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 < T >::type > compT;
static compare < typename std::decay < R >::type > compR; static compare < typename std::decay < R >::type > compR;
...@@ -59,6 +129,14 @@ struct compare < ext::pair < T, R > > { ...@@ -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 > template < class T, class R >
std::string to_string ( const ext::pair < T, R > & value ) { std::string to_string ( const ext::pair < T, R > & value ) {
std::stringstream ss; std::stringstream ss;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment