From 8ec0cd1819a49453ebb83a8815708947e8d0bfd2 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Tue, 27 Sep 2016 15:51:11 +0200 Subject: [PATCH] Doc in TSTL --- tstl/include/type_traits.hpp | 40 +++++++++++++++++----- tstl/include/vector.hpp | 65 ++++++++++++++++++++++++++++++------ 2 files changed, 87 insertions(+), 18 deletions(-) diff --git a/tstl/include/type_traits.hpp b/tstl/include/type_traits.hpp index 8d67e8d9..afc6a425 100644 --- a/tstl/include/type_traits.hpp +++ b/tstl/include/type_traits.hpp @@ -15,18 +15,18 @@ namespace std { template struct iterator_traits { - using value_type = typename T::value_type; - using reference = typename T::reference; - using pointer = typename T::pointer; - using difference_type = typename T::difference_type; + using value_type = typename T::value_type; ///< The value type of the iterator + using reference = typename T::reference; ///< The reference type of the iterator + using pointer = typename T::pointer; ///< The pointer type of the iterator + using difference_type = typename T::difference_type; ///< The difference type of the iterator }; template struct iterator_traits { - using value_type = T; - using reference = T&; - using pointer = T*; - using difference_type = size_t; + using value_type = T; ///< The value type of the iterator + using reference = T&; ///< The reference type of the iterator + using pointer = T*; ///< The pointer type of the iterator + using difference_type = size_t; ///< The difference type of the iterator }; /* remove_reference */ @@ -178,16 +178,25 @@ struct is_pointer{ /* is_reference */ +/*! + * \brief Traits to test if given type is a reference type + */ template struct is_reference { static constexpr const bool value = false; }; +/*! + * \copdoc is_reference + */ template struct is_reference{ static constexpr const bool value = true; }; +/*! + * \copdoc is_reference + */ template struct is_reference{ static constexpr const bool value = true; @@ -195,16 +204,25 @@ struct is_reference{ /* is_array */ +/*! + * \brief Traits to test if given type is an array type + */ template struct is_array { static constexpr const bool value = false; }; +/*! + * \copdoc is_array + */ template struct is_array{ static constexpr const bool value = true; }; +/*! + * \copdoc is_array + */ template struct is_array{ static constexpr const bool value = true; @@ -268,11 +286,17 @@ struct decay { /* is_same */ +/*! + * \brief Traits to test if two types are the same + */ template struct is_same { static constexpr const bool value = false; }; +/*! + * \copydoc is_same + */ template struct is_same { static constexpr const bool value = true; diff --git a/tstl/include/vector.hpp b/tstl/include/vector.hpp index f08dbc2f..0acb61ab 100644 --- a/tstl/include/vector.hpp +++ b/tstl/include/vector.hpp @@ -18,28 +18,40 @@ namespace std { +/*! + * \brief A contiguous container of elements, automatically increasing. + */ template class vector { public: - typedef T value_type; - typedef value_type* pointer_type; - typedef size_t size_type; - typedef value_type* iterator; - typedef const value_type* const_iterator; + using value_type = T; ///< The value type contained in the vector + using pointer_type = value_type*; ///< The pointer type contained in the vector + using size_type = size_t; ///< The size type + using iterator = value_type*; ///< The iterator type + using const_iterator = const value_type*; ///< The const iterator type - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; + using reverse_iterator = std::reverse_iterator; ///< The reverse iterator type + using const_reverse_iterator = std::reverse_iterator; ///< The const reverse iterator type private: - T* data; - uint64_t _size; - uint64_t _capacity; + T* data; ///< The data storage + uint64_t _size; ///< The vector size + uint64_t _capacity; ///< The data capacity public: + /*! + * \brief Constructs en empty vector + */ vector() : data(nullptr), _size(0), _capacity(0) {} + /*! + * \brief Constructs a vector of the given size + */ explicit vector(uint64_t c) : data(new T[c]), _size(0), _capacity(c) {} + /*! + * \brief Construct a vector containing the given values + */ vector(initializer_list values) : data(new T[values.size()]), _size(values.size()), _capacity(values.size()) { std::copy(values.begin(), values.end(), begin()); } @@ -105,50 +117,83 @@ public: //Getters + /*! + * \brief Returns the size of the vector + */ constexpr size_type size() const { return _size; } + /*! + * \brief Indicates if the vector is empty + */ bool empty() const { return _size == 0; } + /*! + * \brief Returns the capacity of the vector + */ constexpr size_type capacity() const { return _capacity; } + /*! + * \brief Returns a const reference to the elemenet at the given position + */ constexpr const value_type& operator[](size_type pos) const { return data[pos]; } + /*! + * \brief Returns a reference to the elemenet at the given position + */ value_type& operator[](size_type pos){ return data[pos]; } + /*! + * \brief Returns a reference to the element at the front of the collection + */ value_type& front(){ return data[0]; } + /*! + * \brief Returns a const reference to the element at the front of the collection + */ const value_type& front() const { return data[0]; } + /*! + * \brief Returns a reference to the element at the back of the collection + */ value_type& back(){ return data[size() - 1]; } + /*! + * \brief Returns a const reference to the element at the back of the collection + */ const value_type& back() const { return data[size() - 1]; } //Modifiers + /*! + * \brief Augments the capacity to at least the given capacity + */ void reserve(size_t new_capacity){ if(new_capacity > capacity()){ ensure_capacity(new_capacity); } } + /*! + * \brief Resize the vector to the given size + */ void resize(size_t new_size){ if(new_size > size()){ ensure_capacity(new_size);