Std::string vs llvm::StringRef

StringRef is not a string class but a reference to a string. It does not allocate nor own the underlying data. In STL, the closest analogy would be std::string_view. References are useful when we don’t want to transfer the ownership of the string data or copy it. Furthermore, StringRef can point to a memory buffer with string-like data that is not an std::string.

1 Like