mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::vector_view: Apply noexcept specifier.
This commit is contained in:
parent
c8deea2e8b
commit
6c7467f07d
1 changed files with 30 additions and 17 deletions
|
@ -15,9 +15,9 @@ namespace ircd
|
|||
{
|
||||
template<class T> struct vector_view;
|
||||
|
||||
template<class T> bool empty(const vector_view<T> &);
|
||||
template<class T> size_t size(const vector_view<T> &);
|
||||
template<class T> T *data(const vector_view<T> &);
|
||||
template<class T> bool empty(const vector_view<T> &) noexcept;
|
||||
template<class T> size_t size(const vector_view<T> &) noexcept;
|
||||
template<class T> T *data(const vector_view<T> &) noexcept;
|
||||
}
|
||||
|
||||
/// Template to represent a contiguous vector or array in a generic way.
|
||||
|
@ -35,19 +35,19 @@ struct ircd::vector_view
|
|||
value_type *_stop { nullptr };
|
||||
|
||||
public:
|
||||
value_type *data() const { return _data; }
|
||||
size_t size() const { return std::distance(_data, _stop); }
|
||||
bool empty() const { return !size(); }
|
||||
value_type *data() const noexcept { return _data; }
|
||||
size_t size() const noexcept { return std::distance(_data, _stop); }
|
||||
bool empty() const noexcept { return !size(); }
|
||||
|
||||
const_iterator begin() const { return data(); }
|
||||
const_iterator end() const { return _stop; }
|
||||
const_iterator cbegin() { return data(); }
|
||||
const_iterator cend() { return _stop; }
|
||||
iterator begin() { return data(); }
|
||||
iterator end() { return _stop; }
|
||||
const_iterator begin() const noexcept { return data(); }
|
||||
const_iterator end() const noexcept { return _stop; }
|
||||
const_iterator cbegin() noexcept { return data(); }
|
||||
const_iterator cend() noexcept { return _stop; }
|
||||
iterator begin() noexcept { return data(); }
|
||||
iterator end() noexcept { return _stop; }
|
||||
|
||||
// Bounds check in debug only.
|
||||
value_type &operator[](const size_t &pos) const
|
||||
value_type &operator[](const size_t &pos) const noexcept
|
||||
{
|
||||
assert(pos < size());
|
||||
return *(data() + pos);
|
||||
|
@ -76,71 +76,84 @@ struct ircd::vector_view
|
|||
}
|
||||
|
||||
vector_view(value_type *const &start, value_type *const &stop)
|
||||
noexcept
|
||||
:_data{start}
|
||||
,_stop{stop}
|
||||
{}
|
||||
|
||||
vector_view(value_type *const &start, const size_t &size)
|
||||
noexcept
|
||||
:vector_view(start, start + size)
|
||||
{}
|
||||
|
||||
vector_view(const std::initializer_list<value_type> &list)
|
||||
noexcept
|
||||
:vector_view(std::begin(list), std::end(list))
|
||||
{}
|
||||
|
||||
template<class U,
|
||||
class A>
|
||||
vector_view(const std::vector<U, A> &v)
|
||||
noexcept
|
||||
:vector_view(v.data(), v.size())
|
||||
{}
|
||||
|
||||
template<class U,
|
||||
class A>
|
||||
vector_view(std::vector<U, A> &v)
|
||||
noexcept
|
||||
:vector_view(v.data(), v.size())
|
||||
{}
|
||||
|
||||
template<size_t SIZE>
|
||||
vector_view(value_type (&buffer)[SIZE])
|
||||
noexcept
|
||||
:vector_view(buffer, SIZE)
|
||||
{}
|
||||
|
||||
template<class U,
|
||||
size_t SIZE>
|
||||
vector_view(const std::array<U, SIZE> &array)
|
||||
noexcept
|
||||
:vector_view(const_cast<pointer>(array.data()), array.size())
|
||||
{}
|
||||
|
||||
template<size_t SIZE>
|
||||
vector_view(std::array<value_type, SIZE> &array)
|
||||
noexcept
|
||||
:vector_view(array.data(), array.size())
|
||||
{}
|
||||
|
||||
// Required for reasonable implicit const conversion of value_type.
|
||||
vector_view(const vector_view<typename std::remove_const<value_type>::type> &v)
|
||||
noexcept
|
||||
:vector_view(v.data(), v.size())
|
||||
{}
|
||||
|
||||
vector_view() = default;
|
||||
vector_view() noexcept = default;
|
||||
vector_view &operator=(const vector_view &) noexcept = default;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
inline T *
|
||||
ircd::data(const vector_view<T> &v)
|
||||
noexcept
|
||||
{
|
||||
return v.data();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t
|
||||
inline size_t
|
||||
ircd::size(const vector_view<T> &v)
|
||||
noexcept
|
||||
{
|
||||
return v.size();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
inline bool
|
||||
ircd::empty(const vector_view<T> &v)
|
||||
noexcept
|
||||
{
|
||||
return v.empty();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue