Skip to content

std::string_view support in Rcpp::wrap() #1357

Closed
@evalon32

Description

@evalon32

Currently, passing a C++17 std::string_view to Rcpp::wrap() follows the generic "iterable" path and creates a character vector (rather than treat the string as a single element as with std::string or Rcpp::String). Is this unintended and would it make sense to change?

My motivating example is this and similar lines in RProtoBuf. Those uses compile, but break at runtime, when the return type of name() et al changes from const std::string& to std::string_view (which it does in protobuf v30). Granted, this could be addressed locally by converting to std::string -- but at the cost of otherwise unnecessary string copies.

A fix seems easy (demo: #1356)

Concerns I anticipate:

  • If any users depend on the current behavior, this would break them.
  • Does this need to be paired with std::wstring_view support for consistency with the rest of the API?
  • What about the plethora of map types containing strings?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions