/* (c) 2014 Glen Joseph Fernandes Distributed under the Boost Software License, Version 1.0. http://boost.org/LICENSE_1_0.txt */ #ifndef MAKE_ALIGNED_HPP #define MAKE_ALIGNED_HPP #include "aligned_ptr.hpp" #include #include template inline aligned_ptr make_aligned(Args&&... args) { auto p = boost::alignment::aligned_alloc(boost:: alignment::alignment_of::value, sizeof(T)); if (!p) { throw std::bad_alloc(); } try { auto q = ::new(p) T(std::forward(args)...); return aligned_ptr(q); } catch (...) { boost::alignment::aligned_free(p); throw; } } #endif