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

continue documenting alib2std

parent 0ed44632
No related branches found
No related tags found
No related merge requests found
...@@ -150,7 +150,7 @@ struct compare < ext::array < T, N > > { ...@@ -150,7 +150,7 @@ struct compare < ext::array < T, N > > {
/** /**
* Overload of to_string function. * Overload of to_string function.
* *
* \param value the value to be converted to string * \param value the array to be converted to string
* *
* \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
......
/* /*
* bitset.hpp * bitset.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: May 04, 2017 * Created on: May 04, 2017
* Author: Jan Travnicek * Author: Jan Travnicek
*/ */
...@@ -17,25 +33,65 @@ ...@@ -17,25 +33,65 @@
   
namespace ext { namespace ext {
   
/**
* Class extending the bitset class from the standard library. Original reason is to allow printing of the container with overloaded operator <<.
*
* The class mimics the behavior of the bitset from the standatd library.
*
* \tparam N the size of the bitset
*/
template < std::size_t N > template < std::size_t N >
class bitset : public std::bitset < N > { class bitset : public std::bitset < N > {
public: public:
/**
* Inherit constructors of the standard bitset
*/
using std::bitset < N >::bitset; using std::bitset < N >::bitset;
/**
* Inherit operator = of the standard bitset
*/
using std::bitset < N >::operator =; using std::bitset < N >::operator =;
#ifndef __clang__ #ifndef __clang__
/**
* Default constructor needed by g++ since it is not inherited
*/
bitset ( ) noexcept : std::bitset < N > ( ) { bitset ( ) noexcept : std::bitset < N > ( ) {
} }
   
/**
* Copy constructor needed by g++ since it is not inherited
*/
bitset ( const bitset & other ) = default; bitset ( const bitset & other ) = default;
   
/**
* Move constructor needed by g++ since it is not inherited
*/
bitset ( bitset && other ) = default; bitset ( bitset && other ) = default;
   
/**
* Copy operator = needed by g++ since it is not inherited
*/
bitset & operator = ( bitset && other ) = default; bitset & operator = ( bitset && other ) = default;
   
/**
* Move operator = needed by g++ since it is not inherited
*/
bitset & operator = ( const bitset & other ) = default; bitset & operator = ( const bitset & other ) = default;
#endif #endif
}; };
   
/**
* Operator to print the bitset to the output stream.
*
* \param out the output stream
* \param bitset the bitset to print
*
* \tparam N the size of the bitset
*
* \return the output stream from the \p out
*/
template < size_t N > template < size_t N >
std::ostream & operator << ( std::ostream & out, const ext::bitset < N > & bitset ) { std::ostream & operator << ( std::ostream & out, const ext::bitset < N > & bitset ) {
out << "["; out << "[";
...@@ -49,8 +105,22 @@ std::ostream & operator << ( std::ostream & out, const ext::bitset < N > & bitse ...@@ -49,8 +105,22 @@ std::ostream & operator << ( std::ostream & out, const ext::bitset < N > & bitse
return out; return out;
} }
   
/**
* Specialisation of the compare structure implementing the three-way comparison
*
* \tparam N the size of the bitset
*/
template < size_t N > template < size_t N >
struct compare < ext::bitset < N > > { struct compare < ext::bitset < N > > {
/**
* 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::bitset < N > & first, const ext::bitset < N > & second ) const { int operator ( ) ( const ext::bitset < N > & first, const ext::bitset < N > & second ) const {
for ( size_t i = 0; i < N; ++i ) { for ( size_t i = 0; i < N; ++i ) {
int res = first [ i ] != second [ i ]; int res = first [ i ] != second [ i ];
...@@ -61,6 +131,13 @@ struct compare < ext::bitset < N > > { ...@@ -61,6 +131,13 @@ struct compare < ext::bitset < N > > {
} }
}; };
   
/**
* Overload of to_string function.
*
* \param value the bitset to be converted to string
*
* \tparam N the size of the bitset
*/
template < size_t N > template < size_t N >
std::string to_string ( const ext::bitset < N > & value ) { std::string to_string ( const ext::bitset < N > & value ) {
std::stringstream ss; std::stringstream ss;
......
/* /*
* deque.hpp * deque.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
*/ */
...@@ -18,25 +34,66 @@ ...@@ -18,25 +34,66 @@
   
namespace ext { namespace ext {
   
/**
* Class extending the deque class from the standard library. Original reason is to allow printing of the container with overloaded operator <<.
*
* 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
*/
template < class T, class Alloc = std::allocator < T > > template < class T, class Alloc = std::allocator < T > >
class deque : public std::deque < T, Alloc >, AllocFix < Alloc > { class deque : public std::deque < T, Alloc >, AllocFix < Alloc > {
public: public:
/**
* Inherit constructors of the standard deque
*/
using std::deque < T, Alloc >::deque; using std::deque < T, Alloc >::deque;
/**
* Inherit operator = of the standard deque
*/
using std::deque < T, Alloc >::operator =; using std::deque < T, Alloc >::operator =;
#ifndef __clang__ #ifndef __clang__
deque ( ) noexcept : std::deque < T, Alloc > ( ) {
}
   
/**
* Default constructor needed by g++ since it is not inherited
*/
deque ( ) = default;
/**
* Copy constructor needed by g++ since it is not inherited
*/
deque ( const deque & other ) = default; deque ( const deque & other ) = default;
   
/**
* Move constructor needed by g++ since it is not inherited
*/
deque ( deque && other ) = default; deque ( deque && other ) = default;
   
/**
* Copy operator = needed by g++ since it is not inherited
*/
deque & operator = ( deque && other ) = default; deque & operator = ( deque && other ) = default;
   
/**
* Move operator = needed by g++ since it is not inherited
*/
deque & operator = ( const deque & other ) = default; deque & operator = ( const deque & other ) = default;
#endif #endif
}; };
   
/**
* Operator to print the deque to the output stream.
*
* \param out the output stream
* \param deque the deque to print
*
* \tparam T the type of values inside the deque
* \tparam Ts ... remaining unimportant template parameters of the deque
*
* \return the output stream from the \p out
*/
template < class T, class ... Ts > template < class T, class ... Ts >
std::ostream & operator <<( std::ostream & out, const ext::deque < T, Ts ... > & list ) { std::ostream & operator <<( std::ostream & out, const ext::deque < T, Ts ... > & list ) {
out << "["; out << "[";
...@@ -54,8 +111,23 @@ std::ostream & operator <<( std::ostream & out, const ext::deque < T, Ts ... > & ...@@ -54,8 +111,23 @@ std::ostream & operator <<( std::ostream & out, const ext::deque < T, Ts ... > &
return out; return out;
} }
   
/**
* 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
*/
template < class T, class ... Ts > template < class T, class ... Ts >
struct compare < ext::deque < T, Ts ... > > { struct compare < ext::deque < 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::deque < T, Ts ... > & first, const ext::deque < T, Ts ... > & second ) const { int operator ()( const ext::deque < T, Ts ... > & first, const ext::deque < T, Ts ... > & second ) const {
if ( first.size ( ) < second.size ( ) ) return -1; if ( first.size ( ) < second.size ( ) ) return -1;
   
...@@ -74,6 +146,14 @@ struct compare < ext::deque < T, Ts ... > > { ...@@ -74,6 +146,14 @@ struct compare < ext::deque < T, Ts ... > > {
   
}; };
   
/**
* Overload of to_string function.
*
* \param value the deque to be converted to string
*
* \tparam T the type of values inside the deque
* \tparam Ts ... remaining unimportant template parameters of the deque
*/
template < class T, class ... Ts > template < class T, class ... Ts >
std::string to_string ( const ext::deque < T, Ts ... > & value ) { std::string to_string ( const ext::deque < T, Ts ... > & 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