comparison 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
comparison
equal deleted inserted replaced
31:5ea2876ac37a 32:651aee870e36
421 421
422 ```cpp 422 ```cpp
423 auto o = my_object("foo"); 423 auto o = my_object("foo");
424 ``` 424 ```
425 425
426 ### String views
427
428 Use `std::string_view` each time you need a string that you will not own, this
429 includes: temporary arguments, return values, compile time constants.
430
431 ```cpp
432 const std::string_view version("1.0");
433
434 auto find(std::string_view id) -> std::optional<int>
435 {
436 if (auto it = foo.find(id); it != foo.end())
437 return it->second;
438
439 return std::nullopt;
440 }
441 ```
442
426 CMake 443 CMake
427 ===== 444 =====
428 445
429 Style 446 Style
430 ----- 447 -----