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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl

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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
index 24efbd5531064d623c8922793359cd78f98022ac..82af93720fd02340daf4dfb2b720decc65fe6fda 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_traits_declaration.tmpl
@@ -9,9 +9,12 @@ struct {{export_attribute}} StructTraits<{{mojom_type}}::DataView,
{%- for field in struct.fields %}
{%- set return_ref = field.kind|is_object_kind or
field.kind|is_any_handle_or_interface_kind %}
+{# We want the field accessor to be const whenever possible to allow #}
+{# structs to be used as map keys. #}
+{%- set const = "" if field.kind|contains_handles else "const" %}
yzshen1 2016/09/20 23:44:40 Does it make sense to name this variable "maybe_co
tibell 2016/09/21 07:10:53 Done.
yzshen1 2016/09/21 23:17:52 It would require adding new attribute in typemap c
tibell 2016/09/22 05:17:23 Done.
{%- if return_ref %}
- static decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
- {{mojom_type}}Ptr& input) {
+ static {{const}} decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
+ {{const}} {{mojom_type}}Ptr& input) {
return input->{{field.name}};
}
{%- else %}

Powered by Google App Engine
This is Rietveld 408576698