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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/union_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/union_traits_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_traits_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_traits_declaration.tmpl
index 583d5bebc1742d3f872336c77b3d57e6b1850547..ce54742003486256c104f4c89ff0c0f2a0e1a37a 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_traits_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_traits_declaration.tmpl
@@ -14,10 +14,22 @@ struct {{export_attribute}} UnionTraits<{{mojom_type}}::DataView,
{%- set return_ref = field.kind|is_object_kind or
field.kind|is_any_handle_or_interface_kind %}
{%- if return_ref %}
+{%- if field.kind|contains_handles %}
static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}())
{{field.name}}({{mojom_type}}Ptr& input) {
return input->get_{{field.name}}();
}
+{%- else %}
+{# We want the field accessor to be const whenever possible to allow
+ structs to be used as map keys. This complicated looking use of decltype
+ etc. gives us a const reference to the field type. #}
+{# TODO(tibell): Output the actual type of the field instead of using decltype
+ to compute it. #}
+ static std::add_lvalue_reference<const std::remove_reference<decltype(std::declval<{{mojom_type}}>().get_{{field.name}}())>::type>::type
yzshen1 2016/09/20 23:44:40 This is quite hard to understand, maybe as you sai
tibell 2016/09/22 05:17:23 Done.
+ {{field.name}}(const {{mojom_type}}Ptr& input) {
+ return input->get_{{field.name}}();
+ }
+{%- endif %}
{%- else %}
static decltype(std::declval<{{mojom_type}}>().get_{{field.name}}())
{{field.name}}(const {{mojom_type}}Ptr& input) {

Powered by Google App Engine
This is Rietveld 408576698