mpd/src/util/OffsetPointer.hxx

25 lines
532 B
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>
#pragma once
#include <cstddef>
/**
* Offset the given pointer by the specified number of bytes.
*/
constexpr void *
2020-09-28 12:16:07 +02:00
OffsetPointer(void *p, std::ptrdiff_t offset) noexcept
{
2022-06-08 20:50:04 +02:00
return static_cast<std::byte *>(p) + offset;
}
/**
* Offset the given pointer by the specified number of bytes.
*/
constexpr const void *
2020-09-28 12:16:07 +02:00
OffsetPointer(const void *p, std::ptrdiff_t offset) noexcept
{
2022-06-08 20:50:04 +02:00
return static_cast<const std::byte *>(p) + offset;
}