27#ifndef OR_TOOLS_UTIL_ALIGNED_MEMORY_H_
28#define OR_TOOLS_UTIL_ALIGNED_MEMORY_H_
44template <
size_t alignment_
bytes,
typename Value>
46 const std::uintptr_t int_ptr =
reinterpret_cast<std::intptr_t
>(ptr);
47 const std::uintptr_t misalignment = int_ptr % alignment_bytes;
48 if (misalignment == 0)
return ptr;
49 return reinterpret_cast<Value*
>(int_ptr - misalignment + alignment_bytes);
55template <
size_t alignment_
bytes,
typename Value>
57 const std::intptr_t int_ptr =
reinterpret_cast<std::intptr_t
>(ptr);
58 const std::intptr_t misalignment = int_ptr % alignment_bytes;
59 return reinterpret_cast<Value*
>(int_ptr - misalignment);
63template <
size_t alignment_
bytes,
typename Value>
65 return reinterpret_cast<std::uintptr_t
>(ptr) % alignment_bytes == 0;
71template <
typename T,
size_t alignment_
bytes>
77template <
typename T,
size_t alignment_
bytes>
78using AlignedVector = std::vector<T, AlignedAllocator<T, alignment_bytes>>;
82namespace use_only_in_tests {
87template <
typename T,
size_t alignment_
bytes,
size_t misalignment_
bytes>
93template <
typename T,
size_t alignment_
bytes,
size_t misalignment_
bytes>
95 std::vector<T, MisalignedAllocator<T, alignment_bytes, misalignment_bytes>>;
std::vector< T, MisalignedAllocator< T, alignment_bytes, misalignment_bytes > > MisalignedVector
In SWIG mode, we don't want anything besides these top-level includes.
bool IsAligned(Value *ptr)
Returns true when ptr is aligned to alignment_bytes bytes.
std::vector< T, AlignedAllocator< T, alignment_bytes > > AlignedVector
Value * AlignUp(Value *ptr)
Value * AlignDown(Value *ptr)