From c121591caa3a1c8ca146bbd2a7b197be90df08c2 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 22 Jan 2024 16:17:06 +0100 Subject: [PATCH 1/2] Initialize std::optional with std::nullopt * ridlbe/c++11/visitors/struct.rb: --- ridlbe/c++11/visitors/struct.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index 202686df..9afc97a0 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -133,6 +133,14 @@ def cxx_member_type "IDL::optional<#{super}>" end end + + def value_initializer + unless optional? + super + else + '{std::nullopt}' + end + end end end end From ffcaa8a89cab70969404db1da077c6ddebaec5e1 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 22 Jan 2024 16:22:40 +0100 Subject: [PATCH 2/2] Reworked optional * ridlbe/c++11/visitors/struct.rb: --- ridlbe/c++11/visitors/struct.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ridlbe/c++11/visitors/struct.rb b/ridlbe/c++11/visitors/struct.rb index 9afc97a0..57b43cc6 100644 --- a/ridlbe/c++11/visitors/struct.rb +++ b/ridlbe/c++11/visitors/struct.rb @@ -59,6 +59,9 @@ def is_array? def value_initializer # When we have an annotation directly applied to this node we are using it + if optional? + return '{std::nullopt}' + end unless node.annotations[:default].first.nil? "{#{node.annotations[:default].first.fields[:value]}}" else @@ -133,14 +136,6 @@ def cxx_member_type "IDL::optional<#{super}>" end end - - def value_initializer - unless optional? - super - else - '{std::nullopt}' - end - end end end end