mirror of
https://github.com/transmission/transmission
synced 2025-01-19 13:30:24 +00:00
953f07375a
* Modernize bitfield.cc: Storage changed to vector of bytes, return vector from getRaw, new Span readonly memory view Modernize bitfield.cc: Code style/review notes Modernize bitfield.cc: Code format * Modernize bitfield.cc: Swap end and begin in bit counting code assertion * Modernize bitfield.cc: Rewrite states and simplify code * Modernize bitfield.cc: Fixing the code and tests * Modernize bitfield.cc: Fixing tests * Modernize bitfield.cc: Formatting; +std::size, +const
45 lines
843 B
C++
45 lines
843 B
C++
/*
|
|
* This file Copyright (C) Mnemosyne LLC
|
|
*
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifndef __TRANSMISSION__
|
|
#error only libtransmission should #include this header.
|
|
#endif
|
|
|
|
/// @brief Readonly non-owning view into a provided memory block with start pointer and size.
|
|
/// In C++20 this appears in standard library as std::span and remotely similar usage.
|
|
template<typename T>
|
|
class Span
|
|
{
|
|
public:
|
|
Span(T const* ptr, size_t size)
|
|
: ptr_{ ptr }
|
|
, size_{ size }
|
|
{
|
|
}
|
|
|
|
T const* begin() const
|
|
{
|
|
return this->ptr_;
|
|
}
|
|
|
|
T const* end() const
|
|
{
|
|
return this->ptr_ + this->size_;
|
|
}
|
|
|
|
[[nodiscard]] size_t size() const
|
|
{
|
|
return size_;
|
|
}
|
|
|
|
private:
|
|
T const* ptr_;
|
|
size_t size_;
|
|
};
|