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

documentation of forward_list and improvements

parent d031786d
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,7 @@ namespace ext {
* The class mimics the behavior of the deque from the standatd library.
*
* \tparam T the type of values inside the deque
* \tparam Ts ... remaining unimportant template parameters of the deque
* \tparam Alloc the allocator of values of type T
*/
template < class T, class Alloc = std::allocator < T > >
class deque : public std::deque < T, Alloc >, AllocFix < Alloc > {
......
/*
* forward_list.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
*/
......@@ -18,24 +34,66 @@
 
namespace ext {
 
/**
* Class extending the forward_list class from the standard library. Original reason is to allow printing of the container with overloaded operator <<.
*
* The class mimics the behavior of the forward_list from the standatd library.
*
* \tparam T the type of values inside the forward_list
* \tparam Alloc the allocator of values of type T
*/
template < class T, class Alloc = std::allocator < T > >
class forward_list : public std::forward_list < T, Alloc >, AllocFix < Alloc > {
public:
/**
* Inherit constructors of the standard forward_list
*/
using std::forward_list < T, Alloc >::forward_list;
/**
* Inherit operator = of the standard forward_list
*/
using std::forward_list < T, Alloc >::operator =;
#ifndef __clang__
/**
* Default constructor needed by g++ since it is not inherited
*/
forward_list ( ) = default;
 
/**
* Copy constructor needed by g++ since it is not inherited
*/
forward_list ( const forward_list & other ) = default;
 
/**
* Move constructor needed by g++ since it is not inherited
*/
forward_list ( forward_list && other ) = default;
 
/**
* Copy operator = needed by g++ since it is not inherited
*/
forward_list & operator = ( forward_list && other ) = default;
 
/**
* Move operator = needed by g++ since it is not inherited
*/
forward_list & operator = ( const forward_list & other ) = default;
#endif
};
 
/**
* Operator to print the forward_list to the output stream.
*
* \param out the output stream
* \param forward_list the forward_list to print
*
* \tparam T the type of values inside the forward_list
* \tparam Ts ... remaining unimportant template parameters of the forward_list
*
* \return the output stream from the \p out
*/
template< class T, class ... Ts >
std::ostream& operator<<(std::ostream& out, const ext::forward_list<T, Ts ... >& forward_list) {
out << "[";
......@@ -51,8 +109,23 @@ std::ostream& operator<<(std::ostream& out, const ext::forward_list<T, Ts ... >&
return out;
}
 
/**
* 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
*/
template<class T, class ... Ts >
struct compare<ext::forward_list<T, Ts ... >> {
/**
* 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_list<T, Ts ... >& first, const ext::forward_list<T, Ts ... >& second) const {
if(first.size() < second.size()) return -1;
if(first.size() > second.size()) return 1;
......@@ -66,6 +139,14 @@ struct compare<ext::forward_list<T, Ts ... >> {
}
};
 
/**
* Overload of to_string function.
*
* \param value the forward_list to be converted to string
*
* \tparam T the type of values inside the forward_list
* \tparam Ts ... remaining unimportant template parameters of the forward_list
*/
template < class T, class ... Ts >
std::string to_string ( const ext::forward_list < T, Ts ... > & value ) {
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