mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 00:28:21 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
130
src/Span.h
130
src/Span.h
|
@ -7,15 +7,16 @@
|
|||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
namespace zeek {
|
||||
namespace zeek
|
||||
{
|
||||
|
||||
/**
|
||||
* Drop-in replacement for C++20's @c std::span with dynamic extent only:
|
||||
* https://en.cppreference.com/w/cpp/container/span. After upgrading to C++20,
|
||||
* this class may get replaced with a type alias instead and/or deprecated.
|
||||
*/
|
||||
template <class T>
|
||||
class Span {
|
||||
template <class T> class Span
|
||||
{
|
||||
public:
|
||||
// -- member types ---------------------------------------------------------
|
||||
|
||||
|
@ -45,39 +46,29 @@ public:
|
|||
|
||||
// -- constructors, destructors, and assignment operators ------------------
|
||||
|
||||
constexpr Span() noexcept : memory_block(nullptr), num_elements(0)
|
||||
{
|
||||
}
|
||||
constexpr Span() noexcept : memory_block(nullptr), num_elements(0) { }
|
||||
|
||||
constexpr Span(pointer ptr, size_t size)
|
||||
: memory_block(ptr), num_elements(size)
|
||||
{
|
||||
}
|
||||
constexpr Span(pointer ptr, size_t size) : memory_block(ptr), num_elements(size) { }
|
||||
|
||||
constexpr Span(pointer first, pointer last)
|
||||
: memory_block(first), num_elements(static_cast<size_t>(last - first))
|
||||
: memory_block(first), num_elements(static_cast<size_t>(last - first))
|
||||
{
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
constexpr Span(element_type (&arr)[Size]) noexcept
|
||||
: memory_block(arr), num_elements(Size)
|
||||
constexpr Span(element_type (&arr)[Size]) noexcept : memory_block(arr), num_elements(Size)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Container,
|
||||
class Data = typename Container::value_type,
|
||||
template <class Container, class Data = typename Container::value_type,
|
||||
class = std::enable_if_t<std::is_convertible_v<Data*, T*>>>
|
||||
Span(Container& xs) noexcept
|
||||
: memory_block(xs.data()), num_elements(xs.size())
|
||||
Span(Container& xs) noexcept : memory_block(xs.data()), num_elements(xs.size())
|
||||
{
|
||||
}
|
||||
|
||||
template <class Container,
|
||||
class Data = typename Container::value_type,
|
||||
template <class Container, class Data = typename Container::value_type,
|
||||
class = std::enable_if_t<std::is_convertible_v<const Data*, T*>>>
|
||||
Span(const Container& xs) noexcept
|
||||
: memory_block(xs.data()), num_elements(xs.size())
|
||||
Span(const Container& xs) noexcept : memory_block(xs.data()), num_elements(xs.size())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -87,40 +78,22 @@ public:
|
|||
|
||||
// -- iterators ------------------------------------------------------------
|
||||
|
||||
constexpr iterator begin() const noexcept
|
||||
{
|
||||
return memory_block;
|
||||
}
|
||||
constexpr iterator begin() const noexcept { return memory_block; }
|
||||
|
||||
constexpr const_iterator cbegin() const noexcept
|
||||
{
|
||||
return memory_block;
|
||||
}
|
||||
constexpr const_iterator cbegin() const noexcept { return memory_block; }
|
||||
|
||||
constexpr iterator end() const noexcept
|
||||
{
|
||||
return begin() + num_elements;
|
||||
}
|
||||
constexpr iterator end() const noexcept { return begin() + num_elements; }
|
||||
|
||||
constexpr const_iterator cend() const noexcept
|
||||
{
|
||||
return cbegin() + num_elements;
|
||||
}
|
||||
constexpr const_iterator cend() const noexcept { return cbegin() + num_elements; }
|
||||
|
||||
constexpr reverse_iterator rbegin() const noexcept
|
||||
{
|
||||
return reverse_iterator{end()};
|
||||
}
|
||||
constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator{end()}; }
|
||||
|
||||
constexpr const_reverse_iterator crbegin() const noexcept
|
||||
{
|
||||
return const_reverse_iterator{end()};
|
||||
}
|
||||
|
||||
constexpr reverse_iterator rend() const noexcept
|
||||
{
|
||||
return reverse_iterator{begin()};
|
||||
}
|
||||
constexpr reverse_iterator rend() const noexcept { return reverse_iterator{begin()}; }
|
||||
|
||||
constexpr const_reverse_iterator crend() const noexcept
|
||||
{
|
||||
|
@ -129,42 +102,21 @@ public:
|
|||
|
||||
// -- element access -------------------------------------------------------
|
||||
|
||||
constexpr reference operator[](size_t index) const noexcept
|
||||
{
|
||||
return memory_block[index];
|
||||
}
|
||||
constexpr reference operator[](size_t index) const noexcept { return memory_block[index]; }
|
||||
|
||||
constexpr reference front() const noexcept
|
||||
{
|
||||
return *memory_block;
|
||||
}
|
||||
constexpr reference front() const noexcept { return *memory_block; }
|
||||
|
||||
constexpr reference back() const noexcept
|
||||
{
|
||||
return (*this)[num_elements - 1];
|
||||
}
|
||||
constexpr reference back() const noexcept { return (*this)[num_elements - 1]; }
|
||||
|
||||
// -- properties -----------------------------------------------------------
|
||||
|
||||
constexpr size_t size() const noexcept
|
||||
{
|
||||
return num_elements;
|
||||
}
|
||||
constexpr size_t size() const noexcept { return num_elements; }
|
||||
|
||||
constexpr size_t size_bytes() const noexcept
|
||||
{
|
||||
return num_elements * sizeof(element_type);
|
||||
}
|
||||
constexpr size_t size_bytes() const noexcept { return num_elements * sizeof(element_type); }
|
||||
|
||||
constexpr bool empty() const noexcept
|
||||
{
|
||||
return num_elements == 0;
|
||||
}
|
||||
constexpr bool empty() const noexcept { return num_elements == 0; }
|
||||
|
||||
constexpr pointer data() const noexcept
|
||||
{
|
||||
return memory_block;
|
||||
}
|
||||
constexpr pointer data() const noexcept { return memory_block; }
|
||||
|
||||
// -- subviews -------------------------------------------------------------
|
||||
|
||||
|
@ -178,10 +130,7 @@ public:
|
|||
return {memory_block + offset, num_elements - offset};
|
||||
}
|
||||
|
||||
constexpr Span first(size_t num_elements) const
|
||||
{
|
||||
return {memory_block, num_elements};
|
||||
}
|
||||
constexpr Span first(size_t num_elements) const { return {memory_block, num_elements}; }
|
||||
|
||||
constexpr Span last(size_t num_elements) const
|
||||
{
|
||||
|
@ -191,28 +140,23 @@ public:
|
|||
private:
|
||||
// -- member variables -----------------------------------------------------
|
||||
|
||||
/// Points to the first element in the contiguous memory block.
|
||||
pointer memory_block;
|
||||
/// Points to the first element in the contiguous memory block.
|
||||
pointer memory_block;
|
||||
|
||||
/// Stores the number of elements in the contiguous memory block.
|
||||
size_t num_elements;
|
||||
};
|
||||
/// Stores the number of elements in the contiguous memory block.
|
||||
size_t num_elements;
|
||||
};
|
||||
|
||||
// -- deduction guides ---------------------------------------------------------
|
||||
|
||||
template <class T>
|
||||
Span(T*, size_t) -> Span<T>;
|
||||
template <class T> Span(T*, size_t) -> Span<T>;
|
||||
|
||||
template <class Iter>
|
||||
Span(Iter, Iter) -> Span<typename std::iterator_traits<Iter>::value_type>;
|
||||
template <class Iter> Span(Iter, Iter) -> Span<typename std::iterator_traits<Iter>::value_type>;
|
||||
|
||||
template <class T, size_t N>
|
||||
Span(T (&)[N]) -> Span<T>;
|
||||
template <class T, size_t N> Span(T (&)[N]) -> Span<T>;
|
||||
|
||||
template <class Container>
|
||||
Span(Container&) -> Span<typename Container::value_type>;
|
||||
template <class Container> Span(Container&) -> Span<typename Container::value_type>;
|
||||
|
||||
template <class Container>
|
||||
Span(const Container&) -> Span<const typename Container::value_type>;
|
||||
template <class Container> Span(const Container&) -> Span<const typename Container::value_type>;
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue