diff options
author | Hans Goudey <h.goudey@me.com> | 2021-04-25 23:06:38 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-04-25 23:06:38 +0300 |
commit | 16b2b33d0194e79fabca7139658d61701c9d8915 (patch) | |
tree | 432019bbf53d1358aaa477deb7100ff9be258d17 /source/blender/blenlib/BLI_span.hh | |
parent | 20142b08239a9fd5e147189462ca7c7bbfd0a972 (diff) |
BLI: Add "first" method to MutableSpan and Vector
This is convenient because having a uniform interface is nice, and
because of the similarity to "last".
Differential Revision: https://developer.blender.org/D11076
Diffstat (limited to 'source/blender/blenlib/BLI_span.hh')
-rw-r--r-- | source/blender/blenlib/BLI_span.hh | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh index c32ba0826df..c3876d4eaf8 100644 --- a/source/blender/blenlib/BLI_span.hh +++ b/source/blender/blenlib/BLI_span.hh @@ -662,6 +662,16 @@ template<typename T> class MutableSpan { } /** + * Return a reference to the first element in the array. This invokes undefined behavior when the + * array is empty. + */ + constexpr T &first() const + { + BLI_assert(size_ > 0); + return data_[0]; + } + + /** * Returns a reference to the last element. This invokes undefined behavior when the array is * empty. */ |