Skip to content

[clang-tidy] Check request: readability-pass-std-string-view-by-value #121615

@denzor200

Description

@denzor200

Since std::string_view is a lightweight object with reference semantic, there is no objective reason to pass it by reference.

void process_1(const std::string_view&) {} // INCORRECT
void process_2(std::string_view&&) {}      // INCORRECT
void process_3(std::string_view) {}        // OK

The exception is when it was passed as an in-out parameter.

void process_and_change(std::string_view& sv_inout) {
    for (char c : sv_inout) {
        // a logic to process input characters...
    }
    sv_inout = get_new_token();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions