2 (c) 2014 Glen Joseph Fernandes
3 <glenjofe -at- gmail.com>
5 Distributed under the Boost Software
7 http://boost.org/LICENSE_1_0.txt
9 #ifndef MAKE_ALIGNED_HPP
10 #define MAKE_ALIGNED_HPP
12 #include "aligned_ptr.hpp"
13 #include <boost/align/aligned_alloc.hpp>
14 #include <boost/align/alignment_of.hpp>
16 template<class T, class... Args>
17 inline aligned_ptr<T> make_aligned(Args&&... args)
19 auto p = boost::alignment::aligned_alloc(boost::
20 alignment::alignment_of<T>::value, sizeof(T));
22 throw std::bad_alloc();
25 auto q = ::new(p) T(std::forward<Args>(args)...);
26 return aligned_ptr<T>(q);
28 boost::alignment::aligned_free(p);