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

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

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Fix hash unit test on Windows 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..1b7cf8954ba9c66719d73d8a05a99d3cbdfa30f6 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
@@ -8,10 +8,16 @@ 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 %}
+ 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.
+ TODO(tibell): Make this check more precise to deal with e.g.
+ custom types which don't contain handles but require non-const
+ reference for serialization. #}
+{%- set maybe_const = "" if field.kind|contains_handles_or_interfaces else "const" %}
{%- if return_ref %}
- static decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
- {{mojom_type}}Ptr& input) {
+ static {{maybe_const}} decltype({{mojom_type}}::{{field.name}})& {{field.name}}(
+ {{maybe_const}} {{mojom_type}}Ptr& input) {
return input->{{field.name}};
}
{%- else %}

Powered by Google App Engine
This is Rietveld 408576698