| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is almost the source from N3656 ("make_unique (Revision 1)"; | 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 | 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 | 7 // "make_unique" to use until we can use C++14. The following changes have been |
| 8 // made: | 8 // made: |
| 9 // - It's called |MakeUnique| instead of |make_unique|. | 9 // - It's called |MakeUnique| instead of |make_unique|. |
| 10 // - It's in the |mojo::util| namespace instead of |std|; this also | 10 // - It's in the |mojo::util| namespace instead of |std|; this also |
| 11 // necessitates adding some |std::|s. | 11 // necessitates adding some |std::|s. |
| 12 // - It's been formatted. | 12 // - It's been formatted. |
| 13 | 13 |
| 14 #ifndef MOJO_EDK_UTIL_MAKE_UNIQUE_H_ | 14 #ifndef MOJO_EDK_UTIL_MAKE_UNIQUE_H_ |
| 15 #define MOJO_EDK_UTIL_MAKE_UNIQUE_H_ | 15 #define MOJO_EDK_UTIL_MAKE_UNIQUE_H_ |
| 16 | 16 |
| 17 #include <cstddef> | 17 #include <stddef.h> |
| 18 |
| 18 #include <memory> | 19 #include <memory> |
| 19 #include <type_traits> | 20 #include <type_traits> |
| 20 #include <utility> | 21 #include <utility> |
| 21 | 22 |
| 22 namespace mojo { | 23 namespace mojo { |
| 23 namespace util { | 24 namespace util { |
| 24 | 25 |
| 25 template <class T> | 26 template <class T> |
| 26 struct _Unique_if { | 27 struct _Unique_if { |
| 27 typedef std::unique_ptr<T> _Single_object; | 28 typedef std::unique_ptr<T> _Single_object; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 48 return std::unique_ptr<T>(new U[n]()); | 49 return std::unique_ptr<T>(new U[n]()); |
| 49 } | 50 } |
| 50 | 51 |
| 51 template <class T, class... Args> | 52 template <class T, class... Args> |
| 52 typename _Unique_if<T>::_Known_bound MakeUnique(Args&&...) = delete; | 53 typename _Unique_if<T>::_Known_bound MakeUnique(Args&&...) = delete; |
| 53 | 54 |
| 54 } // namespace util | 55 } // namespace util |
| 55 } // namespace mojo | 56 } // namespace mojo |
| 56 | 57 |
| 57 #endif // MOJO_EDK_UTIL_MAKE_UNIQUE_H_ | 58 #endif // MOJO_EDK_UTIL_MAKE_UNIQUE_H_ |
| OLD | NEW |