Lightning Talk: C++ String Literals Have the Wrong Type - Jonathan Müller - C++ on Sea 2023

Ғылым және технология

cpponsea.uk/
---
Lightning Talk: String Literals Have the Wrong Type - Jonathan Müller - C++ on Sea 2023
`std::ranges::size("abc")` is `4`, not `3` - it includes the trailing null-terminator. We can fix that with UDLs, NTTPs and TMP.
---
Slides: github.com/philsquared/cppons...
Sponsored By think-cell: www.think-cell.com/en/
---
Jonathan Müller
Jonathan is a library developer at think-cell. In his spare time, he works on various C++ open source libraries for memory allocation, cache-friendly containers, or parsing. He also blogs at foonathan.net and is a member of the C++ standardization committee.
---
C++ on Sea is an annual C++ and coding conference, in Folkestone, in the UK.
- Annual C++ on Sea, C++ conference: cpponsea.uk/
- 2023 Program: cpponsea.uk/2023/schedule/
- Twitter: / cpponsea
---
KZread Videos Filmed, Edited & Optimised by Digital Medium: events.digital-medium.co.uk
#cpp​ #cpponsea​ #cppprogramming

Пікірлер: 7

  • @anon_y_mousse
    @anon_y_mousse7 ай бұрын

    This is why the committee should've added a first-class string type.

  • @Bolpat
    @Bolpat7 ай бұрын

    For working with ranges, do you really need a custom user-defined literal? Doesn't std::string_view already do that?

  • @foonathan

    @foonathan

    4 ай бұрын

    Just for working with ranges, no, std::string_view would be enough. However, std::string_view doesn't provide a constexpr size(), like e.g. std::array, even though the size of the string literal is a compile-time value. By using a custom type with a custom user-defined literal we can correct that, which allows us to create a C string using tc::concat as shown in the end.

  • @szaszm_
    @szaszm_7 ай бұрын

    Great ideas, great library. I hope we can fix that along with other incorrect defaults in the language. I could imagine a module-level declaration of the new defaults, like "use strict" in JS. But I'm afraid that the community will flock to Rust instead, where they got the defaults right (or mostly right), and slowly abandon C++ for new code.

  • @pawees8128
    @pawees81287 ай бұрын

    just use a string_view literal. using namespace std::literals; auto l = "abc"sv; std::cout

  • @guruware8612
    @guruware86127 ай бұрын

    the stud-library... obviously never enuff time to say 'standard' formatting with the fumt-library ?

  • @peterg76yt
    @peterg76yt7 ай бұрын

    A string literal does not have the "wrong type" just because you use it incorrectly.

Келесі