0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::buffer: Add an alignment check util.

This commit is contained in:
Jason Volk 2018-11-16 19:22:44 -08:00
parent adf2de8aed
commit 26ed0ee0e4

View file

@ -65,6 +65,7 @@ namespace ircd::buffer
template<class it> bool operator!(const buffer<it> &buffer);
template<class it> size_t size(const buffer<it> &buffer);
template<class it> const it &data(const buffer<it> &buffer);
template<class it> bool aligned(const buffer<it> &buffer, const size_t &alignment);
template<class it> size_t consume(buffer<it> &buffer, const size_t &bytes);
template<class it> buffer<it> operator+(const buffer<it> &buffer, const size_t &bytes);
template<class it> it copy(it &dest, const it &stop, const const_buffer &);
@ -348,6 +349,16 @@ ircd::buffer::consume(buffer<it> &buffer,
return size(buffer);
}
template<class it>
bool
ircd::buffer::aligned(const buffer<it> &buffer,
const size_t &a)
{
return likely(a)?
uintptr_t(data(buffer)) % a == 0 && size(buffer) % a == 0:
true;
}
template<class it>
const it &
ircd::buffer::data(const buffer<it> &buffer)