#pragma once #include #include #include #include #include template std::unique_ptr make_unique_nothrow(Args &&...args) noexcept(noexcept(T(std::forward(args)...))) { return std::unique_ptr(new (std::nothrow) T(std::forward(args)...)); } template inline typename std::_MakeUniq::__array make_unique_nothrow(size_t num) noexcept { return std::unique_ptr(new (std::nothrow) std::remove_extent_t[num]()); } template std::shared_ptr make_shared_nothrow(Args &&...args) noexcept(noexcept(T(std::forward(args)...))) { return std::shared_ptr(new (std::nothrow) T(std::forward(args)...)); } template bool remove_locked_first_if(std::mutex &mutex, std::forward_list &list, Predicate pred) { std::lock_guard lock(mutex); auto oit = list.before_begin(), it = std::next(oit); while (it != list.end()) { if (pred(*it)) { list.erase_after(oit); return true; } oit = it++; } return false; } // those work only in powers of 2 #define ROUNDDOWN(val, align) ((val) & ~(align - 1)) #define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)