mirror of https://gitee.com/bigwinds/arangodb
added implementation for make_unique
This commit is contained in:
parent
8656010537
commit
72f2c4a80e
|
@ -159,6 +159,7 @@ typedef long suseconds_t;
|
|||
#include "Basics/voc-errors.h"
|
||||
#include "Basics/error.h"
|
||||
#include "Basics/debugging.h"
|
||||
#include "Basics/make_unique.h"
|
||||
#include "Basics/memory.h"
|
||||
#include "Basics/mimetypes.h"
|
||||
#include "Basics/structures.h"
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief High-Performance Database Framework made by triagens
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
|
||||
/// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGODB_BASICS_MAKE_UNIQUE_H
|
||||
#define ARANGODB_BASICS_MAKE_UNIQUE_H 1
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
// VS 2013 and VS 2015 already provide std::make_unique
|
||||
#ifndef _WIN32
|
||||
|
||||
// c++98: 199711 (not supported)
|
||||
// c++11: 201103 (no std::make_unique)
|
||||
// c++14: 201402 (std::make_unique included)
|
||||
|
||||
#if __cplusplus == 201103L
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Provide a make_unique() function for C++11 too
|
||||
/// http://stackoverflow.com/questions/17902405/how-to-implement-make-unique-function-in-c11
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace std {
|
||||
template<class T> struct _Unique_if {
|
||||
typedef unique_ptr<T> _Single_object;
|
||||
};
|
||||
|
||||
template<class T> struct _Unique_if<T[]> {
|
||||
typedef unique_ptr<T[]> _Unknown_bound;
|
||||
};
|
||||
|
||||
template<class T, size_t N> struct _Unique_if<T[N]> {
|
||||
typedef void _Known_bound;
|
||||
};
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Single_object
|
||||
make_unique(Args&&... args) {
|
||||
return unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
typename _Unique_if<T>::_Unknown_bound
|
||||
make_unique(size_t n) {
|
||||
typedef typename remove_extent<T>::type U;
|
||||
return unique_ptr<T>(new U[n]());
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Known_bound
|
||||
make_unique(Args&&...) = delete;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue