Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ptr.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
18#include <cstddef>
19#include <cstdint>
20
21namespace shambase {
22
29 inline bool is_aligned(const void *ptr, size_t alignment) noexcept {
30 auto iptr = reinterpret_cast<std::uintptr_t>(ptr);
31 return !(iptr % alignment);
32 }
33
35 template<class T>
36 inline bool is_aligned(const void *ptr) noexcept {
37 return is_aligned(ptr, alignof(T));
38 }
39
40} // namespace shambase
namespace for basic c++ utilities
bool is_aligned(const void *ptr, size_t alignment) noexcept
Check if a pointer is aligned with the given alignment.
Definition ptr.hpp:29
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.