Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:10:12

0001 /**
0002  * Copyright (c) 2017-present, Facebook, Inc.
0003  * All rights reserved.
0004  *
0005  * This source code is licensed under the BSD-style license found in the
0006  * LICENSE file in the root directory of this source tree.
0007  */
0008 
0009 #pragma once
0010 
0011 #include <memory>
0012 
0013 namespace gloo {
0014 
0015 // make_unique is a C++14 feature. If we don't have 14, we will emulate
0016 // its behavior. This is copied from folly/Memory.h
0017 #if __cplusplus >= 201402L ||                                              \
0018     (defined __cpp_lib_make_unique && __cpp_lib_make_unique >= 201304L) || \
0019     (defined(_MSC_VER) && _MSC_VER >= 1900)
0020 /* using override */ using std::make_unique;
0021 #else
0022 
0023 template<typename T, typename... Args>
0024 typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
0025 make_unique(Args&&... args) {
0026   return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
0027 }
0028 
0029 // Allows 'make_unique<T[]>(10)'. (N3690 s20.9.1.4 p3-4)
0030 template<typename T>
0031 typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type
0032 make_unique(const size_t n) {
0033   return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]());
0034 }
0035 
0036 // Disallows 'make_unique<T[10]>()'. (N3690 s20.9.1.4 p5)
0037 template<typename T, typename... Args>
0038 typename std::enable_if<
0039   std::extent<T>::value != 0, std::unique_ptr<T>>::type
0040 make_unique(Args&&...) = delete;
0041 
0042 #endif
0043 
0044 } // namespace gloo