Skip to content

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

@JohanChane

Description

@JohanChane

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions