Mercurial > template
diff STYLE.md @ 32:651aee870e36
Add paragraph about std::string_view
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 18 Jul 2018 13:55:49 +0200 |
parents | 5ea2876ac37a |
children | 793a60620477 |
line wrap: on
line diff
--- a/STYLE.md Thu Jul 12 09:01:40 2018 +0200 +++ b/STYLE.md Wed Jul 18 13:55:49 2018 +0200 @@ -423,6 +423,23 @@ auto o = my_object("foo"); ``` +### String views + +Use `std::string_view` each time you need a string that you will not own, this +includes: temporary arguments, return values, compile time constants. + +```cpp +const std::string_view version("1.0"); + +auto find(std::string_view id) -> std::optional<int> +{ + if (auto it = foo.find(id); it != foo.end()) + return it->second; + + return std::nullopt; +} +``` + CMake =====