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

Side by Side Diff: base/optional.h

Issue 2792183003: Remove base::is_trivially_destructible and use the standard library. (Closed)
Patch Set: triviallydestruct: rm-tests Created 3 years, 8 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 | « no previous file | base/optional_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef BASE_OPTIONAL_H_ 5 #ifndef BASE_OPTIONAL_H_
6 #define BASE_OPTIONAL_H_ 6 #define BASE_OPTIONAL_H_
7 7
8 #include <type_traits> 8 #include <type_traits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/template_util.h"
12 11
13 namespace base { 12 namespace base {
14 13
15 // Specification: 14 // Specification:
16 // http://en.cppreference.com/w/cpp/utility/optional/in_place_t 15 // http://en.cppreference.com/w/cpp/utility/optional/in_place_t
17 struct in_place_t {}; 16 struct in_place_t {};
18 17
19 // Specification: 18 // Specification:
20 // http://en.cppreference.com/w/cpp/utility/optional/nullopt_t 19 // http://en.cppreference.com/w/cpp/utility/optional/nullopt_t
21 struct nullopt_t { 20 struct nullopt_t {
22 constexpr explicit nullopt_t(int) {} 21 constexpr explicit nullopt_t(int) {}
23 }; 22 };
24 23
25 // Specification: 24 // Specification:
26 // http://en.cppreference.com/w/cpp/utility/optional/in_place 25 // http://en.cppreference.com/w/cpp/utility/optional/in_place
27 constexpr in_place_t in_place = {}; 26 constexpr in_place_t in_place = {};
28 27
29 // Specification: 28 // Specification:
30 // http://en.cppreference.com/w/cpp/utility/optional/nullopt 29 // http://en.cppreference.com/w/cpp/utility/optional/nullopt
31 constexpr nullopt_t nullopt(0); 30 constexpr nullopt_t nullopt(0);
32 31
33 namespace internal { 32 namespace internal {
34 33
35 template <typename T, bool = base::is_trivially_destructible<T>::value> 34 template <typename T, bool = std::is_trivially_destructible<T>::value>
36 struct OptionalStorage { 35 struct OptionalStorage {
37 // Initializing |empty_| here instead of using default member initializing 36 // Initializing |empty_| here instead of using default member initializing
38 // to avoid errors in g++ 4.8. 37 // to avoid errors in g++ 4.8.
39 constexpr OptionalStorage() : empty_('\0') {} 38 constexpr OptionalStorage() : empty_('\0') {}
40 39
41 constexpr explicit OptionalStorage(const T& value) 40 constexpr explicit OptionalStorage(const T& value)
42 : is_null_(false), value_(value) {} 41 : is_null_(false), value_(value) {}
43 42
44 // TODO(alshabalin): Can't use 'constexpr' with std::move until C++14. 43 // TODO(alshabalin): Can't use 'constexpr' with std::move until C++14.
45 explicit OptionalStorage(T&& value) 44 explicit OptionalStorage(T&& value)
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 template <class T> 496 template <class T>
498 struct hash<base::Optional<T>> { 497 struct hash<base::Optional<T>> {
499 size_t operator()(const base::Optional<T>& opt) const { 498 size_t operator()(const base::Optional<T>& opt) const {
500 return opt == base::nullopt ? 0 : std::hash<T>()(*opt); 499 return opt == base::nullopt ? 0 : std::hash<T>()(*opt);
501 } 500 }
502 }; 501 };
503 502
504 } // namespace std 503 } // namespace std
505 504
506 #endif // BASE_OPTIONAL_H_ 505 #endif // BASE_OPTIONAL_H_
OLDNEW
« no previous file with comments | « no previous file | base/optional_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698