From: Adam C. Emerson Date: Tue, 3 May 2016 22:11:55 +0000 (-0400) Subject: common: Add make_unique X-Git-Tag: v12.1.0~10^2~88^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=64acb16354b3812fdcdbb47c1c9c65d81694971d;p=ceph.git common: Add make_unique There are parts of C++14 that are both useful and easy to implement. This is one of them. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/backport14.h b/src/common/backport14.h new file mode 100644 index 000000000000..a7afd49e4d6f --- /dev/null +++ b/src/common/backport14.h @@ -0,0 +1,60 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include + +#ifndef CEPH_COMMON_BACKPORT14_H +#define CEPH_COMMON_BACKPORT14_H + +// Library code from C++14 that can be implemented in C++11. + +namespace ceph { +template +using remove_extent_t = typename std::remove_extent::type; + +namespace _backport14 { +template +struct uniquity { + using datum = std::unique_ptr; +}; + +template +struct uniquity { + using array = std::unique_ptr; +}; + +template +struct uniquity { + using verboten = void; +}; + +template +inline typename uniquity::datum make_unique(Args&&... args) { + return std::unique_ptr(new T(std::forward(args)...)); +} + +template +inline typename uniquity::array make_unique(std::size_t n) { + return std::unique_ptr(new remove_extent_t[n]()); +} + +template +typename uniquity::verboten +make_unique(Args&&...) = delete; +} // namespace _backport14 +using _backport14::make_unique; +} // namespace ceph + +#endif // CEPH_COMMON_BACKPORT14_H