glideapps/quicktype

[FEATURE]: getter return optional<T> reference in C++

Opened this issue · 0 comments

Context (Input, Language)

Input Format: schema
Output Language: C++

Description

The getter should return std::optional<T>& instead of std::optional<T> to avoid unnecessary copy construction.

Current Behaviour / Output

std::optional<std::string> get_field() {
  return field;   // std::optional<std::string> field;
}

BTW. I used --all-properties-optional and --code-format with-getter-setter to generate the above code.

Proposed Behaviour / Output

std::optional<std::string>& get_field() {
  return field;   // std::optional<std::string> field;
}

Solution

Alternatives

Context