Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Side by Side Diff: mojo/edk/system/make_unique.h

Issue 1355673003: EDK: Add a MakeUnique and use it somewhere. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/endpoint_relayer_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This is almost the source from N3656 ("make_unique (Revision 1)";
6 // https://isocpp.org/files/papers/N3656.txt) almost verbatim, so that we have a
7 // "make_unique" to use until we can use C++14. The following changes have been
8 // made:
9 // - It's called |MakeUnique| instead of |make_unique|.
10 // - It's in the |mojo::system| namespace instead of |std|; this also
11 // necessitates adding some |std::|s.
12 // - It's been formatted.
jamesr 2015/09/17 22:07:49 "It is been formatted"?
13
14 #ifndef MOJO_EDK_SYSTEM_MAKE_UNIQUE_H_
15 #define MOJO_EDK_SYSTEM_MAKE_UNIQUE_H_
16
17 #include <cstddef>
18 #include <memory>
19 #include <type_traits>
20 #include <utility>
21
22 namespace mojo {
23 namespace system {
24
25 template <class T>
26 struct _Unique_if {
kulakowski 2015/09/17 22:12:15 Nit: Identifiers starting with an underscore follo
27 typedef std::unique_ptr<T> _Single_object;
28 };
29
30 template <class T>
31 struct _Unique_if<T[]> {
32 typedef std::unique_ptr<T[]> _Unknown_bound;
33 };
34
35 template <class T, size_t N>
36 struct _Unique_if<T[N]> {
37 typedef void _Known_bound;
38 };
39
40 template <class T, class... Args>
41 typename _Unique_if<T>::_Single_object MakeUnique(Args&&... args) {
42 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
43 }
44
45 template <class T>
46 typename _Unique_if<T>::_Unknown_bound MakeUnique(size_t n) {
47 typedef typename std::remove_extent<T>::type U;
48 return std::unique_ptr<T>(new U[n]());
49 }
50
51 template <class T, class... Args>
52 typename _Unique_if<T>::_Known_bound MakeUnique(Args&&...) = delete;
53
54 } // namespace system
55 } // namespace mojo
56
57 #endif // MOJO_EDK_SYSTEM_MAKE_UNIQUE_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/endpoint_relayer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698