aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/misc/unaligned-inl.h
blob: 68e1c9b499e6173ec80e950c9ca2a402d59e71f5 (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
#ifndef UNALIGNED_INL_H_
#error "Direct inclusion of this file is not allowed, include unaligned.h"
// For the sake of sane code completion.
#include "unaligned.h"
#endif

#include <cstring>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

template <class T>
    requires std::is_trivial_v<T>
T UnalignedLoad(const T* ptr)
{
    T value;
    std::memcpy(&value, ptr, sizeof(T));
    return value;
}

template <class T>
    requires std::is_trivial_v<T>
void UnalignedStore(T* ptr, const T& value)
{
    std::memcpy(ptr, &value, sizeof(T));
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT