/* mbed Microcontroller Library * Copyright (c) 2019 ARM Limited * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MSTD_MEMORY_ #define MSTD_MEMORY_ /* * * - includes toolchain's * - For ARM C 5, C++11/14 features: * - std::align * - std::addressof */ #include #ifdef __CC_ARM #include // size_t, ptrdiff_t namespace std { // [ptr.align] inline void *align(size_t alignment, size_t size, void *&ptr, size_t &space) noexcept { /* Behavior is undefined if alignment is not a power of 2 */ uintptr_t addr = reinterpret_cast(ptr); uintptr_t new_addr = (addr + (alignment - 1)) & ~(alignment - 1); uintptr_t pad = new_addr - addr; if (pad + size <= space) { space -= pad; ptr = reinterpret_cast(new_addr); return ptr; } else { return nullptr; } } // [specialized.addressof] template T *addressof(T &arg) noexcept { return reinterpret_cast(const_cast(&reinterpret_cast(arg))); } } // namespace std #endif // __CC_ARM namespace mstd { using std::allocator; using std::uninitialized_copy; using std::uninitialized_fill; using std::uninitialized_fill_n; using std::addressof; using std::align; } #endif // MSTD_MEMORY_