blob: 014297df00e910295dc37fec3bcf773818549b1f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Copyright 2011-2022, Molecular Matters GmbH <[email protected]>
// See LICENSE.txt for licensing details (2-clause BSD License: https://opensource.org/licenses/BSD-2-Clause)
#pragma once
#include "PDB_Macros.h"
#include "PDB_TypeTraits.h"
namespace PDB
{
namespace Pointer
{
// Offsets any pointer by a given number of bytes.
template <typename T, typename U, typename V>
PDB_NO_DISCARD inline T Offset(U* anyPointer, V howManyBytes) PDB_NO_EXCEPT
{
static_assert(PDB::is_pointer<T>::value == true, "Type T must be a pointer type.");
union
{
T as_T;
U* as_U_ptr;
char* as_char_ptr;
};
as_U_ptr = anyPointer;
as_char_ptr += howManyBytes;
return as_T;
}
}
}
|