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

Side by Side Diff: mojo/public/cpp/bindings/string.h

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Remove left-over import Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_STRING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <functional>
10 #include <string> 11 #include <string>
11 12
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "mojo/public/cpp/bindings/lib/array_internal.h" 14 #include "mojo/public/cpp/bindings/lib/array_internal.h"
14 #include "mojo/public/cpp/bindings/type_converter.h" 15 #include "mojo/public/cpp/bindings/type_converter.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 18
18 // A UTF-8 encoded character string that can be null. Provides functions that 19 // A UTF-8 encoded character string that can be null. Provides functions that
19 // are similar to std::string, along with access to the underlying std::string 20 // are similar to std::string, along with access to the underlying std::string
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 }; 187 };
187 188
188 template <> 189 template <>
189 struct TypeConverter<String, const char*> { 190 struct TypeConverter<String, const char*> {
190 // |input| may be null, in which case a null String will be returned. 191 // |input| may be null, in which case a null String will be returned.
191 static String Convert(const char* input) { return String(input); } 192 static String Convert(const char* input) { return String(input); }
192 }; 193 };
193 194
194 } // namespace mojo 195 } // namespace mojo
195 196
197 namespace std {
198
199 template <>
200 struct hash<mojo::String> {
201 size_t operator()(const mojo::String& value) const {
202 // TODO(tibell): Is |value| nullable?
yzshen1 2016/09/20 23:44:40 value.get() won't fail even if |value| is null.
tibell 2016/09/21 07:10:53 Done.
203 return hash<std::string>()(value.get());
204 }
205 };
206
207 } // namespace std
208
196 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_H_ 209 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698