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) { |