
When should I use string_view in an interface?
Jan 17, 2018 · The big drawback of std::string_view is the absence of a c_str() method, resulting in unnecessary, intermediate std::string objects that need to be constructed and allocated. This is …
std::string_view and std::string in utility library interface
Sep 17, 2022 · 2 std::string_view and std::string are two completely different kinds of types. std::string_view is a reference-type, or if you will a view. Like all of them, it doesn't own its data. …
Using std::move in Constructor with value error handling
Dec 20, 2018 · I don't see any moving going on in your second example… also, you should prefer std::string_view -parameters over std::string const&. std::string or std::string&& is only superior when …
Sink or non-sink API's? - Software Engineering Stack Exchange
Mar 13, 2023 · For example, std::string_view is a fine replacement for a const std::string& function argument. The point here is that the C++ language guarantees that function arguments will live as …
error handling - Should I use the "die" idiom in C++? - Software ...
Jun 27, 2022 · As I understand the rationale behind die, programming languages like Perl and PHP create individual web pages by running a script in a process. Writing die essentially means "The web …
How does std::string in c++ allocate memory? [closed]
I've noticed that the string library doesn't require one to allocate space before writing the input/output. How does the string library allocate that memory dynamically, i know of the 'new' keyword...
Alternative to the Visitor Design Pattern - Software Engineering Stack ...
Sep 24, 2021 · I have been trying to come up with a method to "serialize" various objects into various different formats. For example: class Shape { public: virtual std::string_view name() const = ...
Constructor vs casting operator - Software Engineering Stack Exchange
Jan 11, 2015 · One instructive example of using a type conversion operator in the Standard library is the conversion from std::string to std::string_view. Consider the simple code:
c++ - const function parameters and default behavior - Software ...
Jan 17, 2020 · Say I have a C++ function /** * @param path If empty, the system default is used */ void foo (const std::string& path); And in my implementation I have a default handling for empty paths voi...
c++ - Is switching sub-class at runtime a proper use case for ...
Sep 10, 2020 · Just for info: a function that does that is called a factory. (And a dependency injection container mentioned by amon is essentially an object (usually provided by a library) that's in part a …