const corrections

This commit is contained in:
Mathew Sutcliffe
2014-01-28 20:19:06 +00:00
parent d48d8ed951
commit 7c8aa8226d
3 changed files with 19 additions and 12 deletions

View File

@@ -110,12 +110,12 @@ namespace BlackMisc
iterator end() { return pimpl() ? pimpl()->end() : iterator(); } iterator end() { return pimpl() ? pimpl()->end() : iterator(); }
/*! /*!
* \brief Returns iterator one past the end of the collection. * \brief Returns const iterator one past the end of the collection.
*/ */
const_iterator end() const { return pimpl() ? pimpl()->end() : const_iterator(); } const_iterator end() const { return pimpl() ? pimpl()->end() : const_iterator(); }
/*! /*!
* \brief Returns iterator one past the end of the collection. * \brief Returns const iterator one past the end of the collection.
*/ */
const_iterator cend() const { return pimpl() ? pimpl()->cend() : const_iterator(); } const_iterator cend() const { return pimpl() ? pimpl()->cend() : const_iterator(); }
@@ -176,6 +176,7 @@ namespace BlackMisc
* \brief Efficient find method using the find of the implementation container. Typically O(log n). * \brief Efficient find method using the find of the implementation container. Typically O(log n).
* \return An iterator to the position of the found element, or the end iterator if not found. * \return An iterator to the position of the found element, or the end iterator if not found.
* \pre The sequence must be initialized. * \pre The sequence must be initialized.
* \warning Take care that the returned non-const iterator is not compared with a const iterator.
*/ */
iterator find(const T &value) { Q_ASSERT(pimpl()); return pimpl()->find(value); } iterator find(const T &value) { Q_ASSERT(pimpl()); return pimpl()->find(value); }

View File

@@ -91,7 +91,7 @@ namespace BlackMisc
template <class Predicate> template <class Predicate>
bool contains(Predicate p) const bool contains(Predicate p) const
{ {
return std::any_of(derived().begin(), derived().end(), p); return std::any_of(derived().cbegin(), derived().cend(), p);
} }
/*! /*!
@@ -99,7 +99,7 @@ namespace BlackMisc
*/ */
bool contains(const T &object) const bool contains(const T &object) const
{ {
return derived().find(object) != derived().end(); return derived().find(object) != derived().cend();
} }
/*! /*!
@@ -156,7 +156,7 @@ namespace BlackMisc
{ {
QString str; QString str;
// qualifying stringify with this-> to workaround bug in GCC 4.7.2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56402 // qualifying stringify with this-> to workaround bug in GCC 4.7.2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56402
std::for_each(derived().begin(), derived().end(), [ & ](const T &value) { str += (str.isEmpty() ? "{" : ",") + this->stringify(value, i18n); }); std::for_each(derived().cbegin(), derived().cend(), [ & ](const T &value) { str += (str.isEmpty() ? "{" : ",") + this->stringify(value, i18n); });
if (str.isEmpty()) { str = "{"; } if (str.isEmpty()) { str = "{"; }
return str += "}"; return str += "}";
} }
@@ -183,7 +183,7 @@ namespace BlackMisc
//const auto &o = static_cast<const CContainerBase &>(other); //const auto &o = static_cast<const CContainerBase &>(other);
//if (derived().size() < o.derived().size()) { return -1; } //if (derived().size() < o.derived().size()) { return -1; }
//if (derived().size() > o.derived().size()) { return 1; } //if (derived().size() > o.derived().size()) { return 1; }
//for (auto i1 = derived().begin(), i2 = o.derived().begin(); i1 != derived().end() && i2 != o.derived().end(); ++i1, ++i2) //for (auto i1 = derived().cbegin(), i2 = o.derived().cbegin(); i1 != derived().cend() && i2 != o.derived().cend(); ++i1, ++i2)
//{ //{
// if (*i1 < *i2) { return -1; } // if (*i1 < *i2) { return -1; }
// if (*i1 > *i2) { return 1; } // if (*i1 > *i2) { return 1; }
@@ -194,7 +194,7 @@ namespace BlackMisc
virtual void marshallToDbus(QDBusArgument &argument) const virtual void marshallToDbus(QDBusArgument &argument) const
{ {
argument.beginArray(qMetaTypeId<T>()); argument.beginArray(qMetaTypeId<T>());
std::for_each(derived().begin(), derived().end(), [ & ](const T &value) { argument << value; }); std::for_each(derived().cbegin(), derived().cend(), [ & ](const T &value) { argument << value; });
argument.endArray(); argument.endArray();
} }

View File

@@ -95,12 +95,12 @@ namespace BlackMisc
iterator begin() { return pimpl() ? pimpl()->begin() : iterator(); } iterator begin() { return pimpl() ? pimpl()->begin() : iterator(); }
/*! /*!
* \brief Returns iterator at the beginning of the sequence. * \brief Returns const iterator at the beginning of the sequence.
*/ */
const_iterator begin() const { return pimpl() ? pimpl()->begin() : const_iterator(); } const_iterator begin() const { return pimpl() ? pimpl()->begin() : const_iterator(); }
/*! /*!
* \brief Returns iterator at the beginning of the sequence. * \brief Returns const iterator at the beginning of the sequence.
*/ */
const_iterator cbegin() const { return pimpl() ? pimpl()->cbegin() : const_iterator(); } const_iterator cbegin() const { return pimpl() ? pimpl()->cbegin() : const_iterator(); }
@@ -110,12 +110,12 @@ namespace BlackMisc
iterator end() { return pimpl() ? pimpl()->end() : iterator(); } iterator end() { return pimpl() ? pimpl()->end() : iterator(); }
/*! /*!
* \brief Returns iterator one past the end of the sequence. * \brief Returns const iterator one past the end of the sequence.
*/ */
const_iterator end() const { return pimpl() ? pimpl()->end() : const_iterator(); } const_iterator end() const { return pimpl() ? pimpl()->end() : const_iterator(); }
/*! /*!
* \brief Returns iterator one past the end of the sequence. * \brief Returns const iterator one past the end of the sequence.
*/ */
const_iterator cend() const { return pimpl() ? pimpl()->cend() : const_iterator(); } const_iterator cend() const { return pimpl() ? pimpl()->cend() : const_iterator(); }
@@ -221,8 +221,14 @@ namespace BlackMisc
/*! /*!
* \brief Return an iterator to the first element equal to the given object, or the end iterator if not found. O(n). * \brief Return an iterator to the first element equal to the given object, or the end iterator if not found. O(n).
* \warning Take care that the returned non-const iterator is not compared with a const iterator.
*/ */
iterator find(const T &object) const { return std::find(begin(), end(), object); } iterator find(const T &object) { return std::find(begin(), end(), object); }
/*!
* \brief Return an iterator to the first element equal to the given object, or the end iterator if not found. O(n).
*/
const_iterator find(const T &object) const { return std::find(cbegin(), cend(), object); }
/*! /*!
* \brief Modify by applying a value map to each element for which a given predicate returns true. * \brief Modify by applying a value map to each element for which a given predicate returns true.