aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/array_ref.h
diff options
context:
space:
mode:
authorAlexander Fokin <apfokin@gmail.com>2022-02-10 16:45:38 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:38 +0300
commit863a59a65247c24db7cb06789bc5cf79d04da32f (patch)
tree139dc000c8cd4a40f5659e421b7c75135d080307 /util/generic/array_ref.h
parentf64e95a9eb9ab03240599eb9581c5a9102426a96 (diff)
downloadydb-863a59a65247c24db7cb06789bc5cf79d04da32f.tar.gz
Restoring authorship annotation for Alexander Fokin <apfokin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/generic/array_ref.h')
-rw-r--r--util/generic/array_ref.h130
1 files changed, 65 insertions, 65 deletions
diff --git a/util/generic/array_ref.h b/util/generic/array_ref.h
index 1ac60ac7d3..a67cf93bf3 100644
--- a/util/generic/array_ref.h
+++ b/util/generic/array_ref.h
@@ -3,30 +3,30 @@
#include <util/generic/yexception.h>
#include <algorithm>
-#include <initializer_list>
+#include <initializer_list>
#include <iterator>
-/**
- * `TArrayRef` works pretty much like `std::span` with dynamic extent, presenting
- * an array-like interface into a contiguous sequence of objects.
- *
- * It can be used at interface boundaries instead of `TVector` or
- * pointer-size pairs, and is actually a preferred way to pass contiguous data
- * into functions.
- *
- * Note that `TArrayRef` can be auto-constructed from any contiguous container
- * (with `size` and `data` members), and thus you don't have to change client code
+/**
+ * `TArrayRef` works pretty much like `std::span` with dynamic extent, presenting
+ * an array-like interface into a contiguous sequence of objects.
+ *
+ * It can be used at interface boundaries instead of `TVector` or
+ * pointer-size pairs, and is actually a preferred way to pass contiguous data
+ * into functions.
+ *
+ * Note that `TArrayRef` can be auto-constructed from any contiguous container
+ * (with `size` and `data` members), and thus you don't have to change client code
* when switching over from passing `TVector` to `TArrayRef`.
- *
- * Note that `TArrayRef` has the same const-semantics as raw pointers:
- * - `TArrayRef<T>` is a non-const reference to non-const data (like `T*`);
- * - `TArrayRef<const T>` is a non-const reference to const data (like `const T*`);
- * - `const TArrayRef<T>` is a const reference to non-const data (like `T* const`);
- * - `const TArrayRef<const T>` is a const reference to const data (like `const T* const`).
- */
-template <class T>
+ *
+ * Note that `TArrayRef` has the same const-semantics as raw pointers:
+ * - `TArrayRef<T>` is a non-const reference to non-const data (like `T*`);
+ * - `TArrayRef<const T>` is a non-const reference to const data (like `const T*`);
+ * - `const TArrayRef<T>` is a const reference to non-const data (like `T* const`);
+ * - `const TArrayRef<const T>` is a const reference to const data (like `const T* const`).
+ */
+template <class T>
class TArrayRef {
-public:
+public:
using iterator = T*;
using const_iterator = const T*;
using reference = T&;
@@ -36,55 +36,55 @@ public:
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
constexpr inline TArrayRef() noexcept
- : T_(nullptr)
- , S_(0)
- {
- }
+ : T_(nullptr)
+ , S_(0)
+ {
+ }
constexpr inline TArrayRef(T* data, size_t len) noexcept
- : T_(data)
- , S_(len)
- {
- }
+ : T_(data)
+ , S_(len)
+ {
+ }
constexpr inline TArrayRef(T* begin, T* end) noexcept
- : T_(begin)
- , S_(end - begin)
- {
- }
+ : T_(begin)
+ , S_(end - begin)
+ {
+ }
constexpr inline TArrayRef(std::initializer_list<T> list) noexcept
- : T_(list.begin())
- , S_(list.size())
- {
- }
-
- template <class Container>
+ : T_(list.begin())
+ , S_(list.size())
+ {
+ }
+
+ template <class Container>
constexpr inline TArrayRef(Container&& container, decltype(std::declval<T*&>() = container.data(), nullptr) = nullptr) noexcept
- : T_(container.data())
- , S_(container.size())
- {
- }
+ : T_(container.data())
+ , S_(container.size())
+ {
+ }
- template <size_t N>
+ template <size_t N>
constexpr inline TArrayRef(T (&array)[N]) noexcept
- : T_(array)
- , S_(N)
- {
- }
+ : T_(array)
+ , S_(N)
+ {
+ }
template <class TT, typename = std::enable_if_t<std::is_same<std::remove_const_t<T>, std::remove_const_t<TT>>::value>>
- bool operator==(const TArrayRef<TT>& other) const noexcept {
+ bool operator==(const TArrayRef<TT>& other) const noexcept {
return (S_ == other.size()) && std::equal(begin(), end(), other.begin());
- }
+ }
constexpr inline T* data() const noexcept {
- return T_;
- }
+ return T_;
+ }
constexpr inline size_t size() const noexcept {
- return S_;
- }
+ return S_;
+ }
constexpr size_t size_bytes() const noexcept {
return (size() * sizeof(T));
@@ -153,7 +153,7 @@ public:
constexpr inline explicit operator bool() const noexcept {
return (S_ > 0);
}
-
+
/**
* Obtains a ref that is a view over the first `count` elements of this TArrayRef.
*
@@ -220,11 +220,11 @@ public:
return static_cast<yssize_t>(this->size());
}
-private:
- T* T_;
- size_t S_;
-};
-
+private:
+ T* T_;
+ size_t S_;
+};
+
/**
* Obtains a view to the object representation of the elements of the TArrayRef arrayRef.
*
@@ -251,14 +251,14 @@ TArrayRef<char> as_writable_bytes(TArrayRef<T> arrayRef) noexcept {
template <class Range>
constexpr TArrayRef<const typename Range::value_type> MakeArrayRef(const Range& range) {
- return TArrayRef<const typename Range::value_type>(range);
+ return TArrayRef<const typename Range::value_type>(range);
}
template <class Range>
constexpr TArrayRef<typename Range::value_type> MakeArrayRef(Range& range) {
- return TArrayRef<typename Range::value_type>(range);
+ return TArrayRef<typename Range::value_type>(range);
}
-
+
template <class Range>
constexpr TArrayRef<const typename Range::value_type> MakeConstArrayRef(const Range& range) {
return TArrayRef<const typename Range::value_type>(range);
@@ -269,10 +269,10 @@ constexpr TArrayRef<const typename Range::value_type> MakeConstArrayRef(Range& r
return TArrayRef<const typename Range::value_type>(range);
}
-template <class T>
+template <class T>
constexpr TArrayRef<T> MakeArrayRef(T* data, size_t size) {
- return TArrayRef<T>(data, size);
-}
+ return TArrayRef<T>(data, size);
+}
template <class T>
constexpr TArrayRef<T> MakeArrayRef(T* begin, T* end) {