]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/backport14.h
d56e24c3e512f821f32f3fda7edaf2210371a0dd
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
16 #include <type_traits>
18 #ifndef CEPH_COMMON_BACKPORT14_H
19 #define CEPH_COMMON_BACKPORT14_H
21 // Library code from C++14 that can be implemented in C++11.
25 using remove_extent_t
= typename
std::remove_extent
<T
>::type
;
27 using remove_reference_t
= typename
std::remove_reference
<T
>::type
;
29 using result_of_t
= typename
std::result_of
<T
>::type
;
31 namespace _backport14
{
34 using datum
= std::unique_ptr
<T
>;
38 struct uniquity
<T
[]> {
39 using array
= std::unique_ptr
<T
[]>;
42 template<typename T
, std::size_t N
>
43 struct uniquity
<T
[N
]> {
44 using verboten
= void;
47 template<typename T
, typename
... Args
>
48 inline typename uniquity
<T
>::datum
make_unique(Args
&&... args
) {
49 return std::unique_ptr
<T
>(new T(std::forward
<Args
>(args
)...));
53 inline typename uniquity
<T
>::array
make_unique(std::size_t n
) {
54 return std::unique_ptr
<T
>(new remove_extent_t
<T
>[n
]());
57 template<typename T
, class... Args
>
58 typename uniquity
<T
>::verboten
59 make_unique(Args
&&...) = delete;
61 // The constexpr variant of std::max().
63 constexpr const T
& max(const T
& a
, const T
& b
) {
66 } // namespace _backport14
68 namespace _backport17
{
70 constexpr auto size(const C
& c
) -> decltype(c
.size()) {
74 template <typename T
, std::size_t N
>
75 constexpr std::size_t size(const T (&array
)[N
]) noexcept
{
78 } // namespace _backport17
79 using _backport14::make_unique
;
80 using _backport17::size
;
81 using _backport14::max
;
84 #endif // CEPH_COMMON_BACKPORT14_H