]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/align/example/make_aligned.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / align / example / make_aligned.hpp
CommitLineData
7c673cae
FG
1/*
2(c) 2014 Glen Joseph Fernandes
3<glenjofe -at- gmail.com>
4
5Distributed under the Boost Software
6License, Version 1.0.
7http://boost.org/LICENSE_1_0.txt
8*/
9#ifndef MAKE_ALIGNED_HPP
10#define MAKE_ALIGNED_HPP
11
12#include "aligned_ptr.hpp"
13#include <boost/align/aligned_alloc.hpp>
14#include <boost/align/alignment_of.hpp>
15
16template<class T, class... Args>
17inline aligned_ptr<T> make_aligned(Args&&... args)
18{
19 auto p = boost::alignment::aligned_alloc(boost::
20 alignment::alignment_of<T>::value, sizeof(T));
21 if (!p) {
22 throw std::bad_alloc();
23 }
24 try {
25 auto q = ::new(p) T(std::forward<Args>(args)...);
26 return aligned_ptr<T>(q);
27 } catch (...) {
28 boost::alignment::aligned_free(p);
29 throw;
30 }
31}
32
33#endif