diff options
author | Max Kellermann <max@duempel.org> | 2014-03-01 07:25:17 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-03-01 07:49:13 +0100 |
commit | 4ba7427fa0f4c8495df331829eb67b27be9c9078 (patch) | |
tree | d34390e68bcd7a26145ea308ea0ee842d637ba32 /src/util | |
parent | 9dc5335e3e4e07371cfae96eca2cb5b2a93c8dd2 (diff) | |
download | mpd-4ba7427fa0f4c8495df331829eb67b27be9c9078.tar.gz mpd-4ba7427fa0f4c8495df331829eb67b27be9c9078.tar.xz mpd-4ba7427fa0f4c8495df331829eb67b27be9c9078.zip |
util/{Const,Writable}Buffer: add operator[]
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/ConstBuffer.hxx | 11 | ||||
-rw-r--r-- | src/util/WritableBuffer.hxx | 11 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/util/ConstBuffer.hxx b/src/util/ConstBuffer.hxx index 7f1fa5aa6..6754cb065 100644 --- a/src/util/ConstBuffer.hxx +++ b/src/util/ConstBuffer.hxx @@ -143,6 +143,17 @@ struct ConstBuffer { constexpr const_iterator cend() const { return data + size; } + +#ifdef NDEBUG + constexpr +#endif + const T &operator[](size_type i) const { +#ifndef NDEBUG + assert(i < size); +#endif + + return data[i]; + } }; #endif diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx index 64e6d0c62..d13f80867 100644 --- a/src/util/WritableBuffer.hxx +++ b/src/util/WritableBuffer.hxx @@ -145,6 +145,17 @@ struct WritableBuffer { constexpr const_iterator cend() const { return data + size; } + +#ifdef NDEBUG + constexpr +#endif + T &operator[](size_type i) const { +#ifndef NDEBUG + assert(i < size); +#endif + + return data[i]; + } }; #endif |