C++ Weekly With Jason Turner
C++ Weekly With Jason Turner
  • 502
  • 8 038 862
C++ Weekly - Ep 430 - How Short String Optimizations Work
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟
Upcoming Workshop: Understanding Object Lifetime, C++ On Sea, July 2, 2024
► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html
Upcoming Workshop: C++ Best Practices, NDC TechTown, Sept 9-10, 2024
► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c
CLion is a cross-platform JetBrains IDE for C and C++ with:
- A smart C and C++ editor to navigate and maintain your code base productively.
- Code analysis with quick-fixes to identify and fix bugs and style inconsistencies.
- An integrated debugger - along with other essential tools from the ecosystem - available
straight out of the box.
- And much more!
jb.gg/clion_ide code: CppWeeklyCLion
Episode details: github.com/lefticus/cpp_weekly/issues/98
T-SHIRTS AVAILABLE!
► The best C++ T-Shirts anywhere! my-store-d16a2f.creator-spring.com/
WANT MORE JASON?
► My Training Classes: emptycrate.com/training.html
► Follow me on twitter: lefticus
SUPPORT THE CHANNEL
► Patreon: www.patreon.com/lefticus
► Github Sponsors: github.com/sponsors/lefticus
► Paypal Donation: www.paypal.com/donate/?hosted_button_id=PQ4A2V6ZZFQEU
GET INVOLVED
► Video Idea List: github.com/lefticus/cpp_weekly/issues
JASON'S BOOKS
► C++23 Best Practices
Leanpub Ebook: leanpub.com/cpp23_best_practices/
► C++ Best Practices
Amazon Paperback: amzn.to/3wpAU3Z
Leanpub Ebook: leanpub.com/cppbestpractices
JASON'S PUZZLE BOOKS
► Object Lifetime Puzzlers Book 1
Amazon Paperback: amzn.to/3g6Ervj
Leanpub Ebook: leanpub.com/objectlifetimepuzzlers_book1
► Object Lifetime Puzzlers Book 2
Amazon Paperback: amzn.to/3whdUDU
Leanpub Ebook: leanpub.com/objectlifetimepuzzlers_book2
► Object Lifetime Puzzlers Book 3
Leanpub Ebook: leanpub.com/objectlifetimepuzzlers_book3
► Copy and Reference Puzzlers Book 1
Amazon Paperback: amzn.to/3g7ZVb9
Leanpub Ebook: leanpub.com/copyandreferencepuzzlers_book1
► Copy and Reference Puzzlers Book 2
Amazon Paperback: amzn.to/3X1LOIx
Leanpub Ebook: leanpub.com/copyandreferencepuzzlers_book2
► Copy and Reference Puzzlers Book 3
Leanpub Ebook: leanpub.com/copyandreferencepuzzlers_book3
► OpCode Puzzlers Book 1
Amazon Paperback: amzn.to/3KCNJg6
Leanpub Ebook: leanpub.com/opcodepuzzlers_book1
RECOMMENDED BOOKS
► Bjarne Stroustrup's A Tour of C++ (now with C++20/23!): amzn.to/3X4Wypr
AWESOME PROJECTS
► The C++ Starter Project - Gets you started with Best Practices Quickly - github.com/cpp-best-practices/cpp_starter_project
► C++ Best Practices Forkable Coding Standards - github.com/cpp-best-practices/cppbestpractices
O'Reilly VIDEOS
► Inheritance and Polymorphism in C++ - www.oreilly.com/library/view/inheritance-and-polymorphism/9781491961933/
► Learning C++ Best Practices - www.oreilly.com/library/view/learning-c-best/9781491954898/
zhlédnutí: 7 997

Video

C++ Weekly - Ep 429 - C++26's Parameter Pack Indexing
zhlédnutí 7KPřed 19 hodinami
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c Episode details: github.com/lefticus/cpp_weekly/issues/376 T-SHIRTS...
C++ Weekly - Ep 428 - C++23's Coroutine Support: std::generator
zhlédnutí 7KPřed 14 dny
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c CLion is a cross-platform JetBrains IDE for C and C with: - A smart...
C++ Weekly - Ep 427 - Simple Generators Without Coroutines
zhlédnutí 9KPřed 21 dnem
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c Episode details: github.com/lefticus/cpp_weekly/issues/304 T-SHIRTS...
C++ Weekly - Ep 426 - Lambdas As State Machines
zhlédnutí 13KPřed 28 dny
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c CLion is a cross-platform JetBrains IDE for C and C with: - A smart...
C++ Weekly - Ep 425 - Using string_view, span, and Pointers Safely!
zhlédnutí 11KPřed měsícem
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c This episode is sponsored by think-cell. think-cell.com/cppweekly E...
C++ Weekly - Ep 424 - .reset vs →reset()
zhlédnutí 10KPřed měsícem
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c CLion is a cross-platform JetBrains IDE for C and C with: - A smart...
C++ Weekly - Ep 423 - Complete Guide to Attributes Through C++23
zhlédnutí 9KPřed měsícem
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c This episode is sponsored by think-cell. think-cell.com/cppweekly E...
C++ Weekly - Ep 422 - Moving from C++20 to C++23
zhlédnutí 9KPřed měsícem
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c Episode details: github.com/lefticus/cpp_weekly/issues/359 T-SHIRTS...
C++ Weekly - Ep 421 - You're Using optional, variant, pair, tuple, any, and expected Wrong!
zhlédnutí 25KPřed 2 měsíci
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c This episode is sponsored by think-cell. think-cell.com/cppweekly E...
C++ Weekly - Ep 420 - Moving From C++17 to C++20 (More constexpr!)
zhlédnutí 8KPřed 2 měsíci
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c Episode details: github.com/lefticus/cpp_weekly/issues/359 T-SHIRTS...
C++ Weekly - Ep 419 - The Important Parts of C++23
zhlédnutí 13KPřed 2 měsíci
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c This episode is sponsored by think-cell. think-cell.com/cppweekly E...
CS101++ - What Are Open Source and GitHub?
zhlédnutí 1,5KPřed 2 měsíci
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c github.com/lefticus/cpp_weekly/discussions/categories/cs101 for ope...
CS101++ - What is`goto`?
zhlédnutí 1,6KPřed 2 měsíci
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c github.com/lefticus/cpp_weekly/discussions/categories/cs101 for ope...
C++ Weekly - Ep 418 - Moving From C++14 to C++17
zhlédnutí 7KPřed 2 měsíci
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟ Upcoming Workshop: Understanding Object Lifetime, C On Sea, July 2, 2024 ► cpponsea.uk/2024/sessions/understanding-object-lifetime-for-efficient-and-safer-cpp.html Upcoming Workshop: C Best Practices, NDC TechTown, Sept 9-10, 2024 ► ndctechtown.com/workshops/c-best-practices/4ceb8f7cf86c Create anything, find anything, fix anything, and navigate to anyth...
CS101++ - What is a `for` Loop?
zhlédnutí 1,2KPřed 2 měsíci
CS101 - What is a `for` Loop?
CS101++ - What is a `do` Loop?
zhlédnutí 1,1KPřed 3 měsíci
CS101 - What is a `do` Loop?
C++ Weekly - Ep 417 - Turbocharge Your Build With Mold?
zhlédnutí 6KPřed 3 měsíci
C Weekly - Ep 417 - Turbocharge Your Build With Mold?
CS101++ - What Are `if`/`else` Statements?
zhlédnutí 1,3KPřed 3 měsíci
CS101 - What Are `if`/`else` Statements?
CS101++ - What is a `while` Loop?
zhlédnutí 1,4KPřed 3 měsíci
CS101 - What is a `while` Loop?
C++ Weekly - Ep 416 - Moving From C++11 to C++14
zhlédnutí 6KPřed 3 měsíci
C Weekly - Ep 416 - Moving From C 11 to C 14
CS101++ - What Are Truth Tables?
zhlédnutí 1,7KPřed 3 měsíci
CS101 - What Are Truth Tables?
CS101++ - What Are Computability and the Halting Problem?
zhlédnutí 2,1KPřed 3 měsíci
CS101 - What Are Computability and the Halting Problem?
C++ Weekly - Ep 415 - Moving From C++98 to C++11
zhlédnutí 8KPřed 3 měsíci
C Weekly - Ep 415 - Moving From C 98 to C 11
CS101++ - Exploring Circuit Simulation Tools: Online & Offline
zhlédnutí 2,5KPřed 3 měsíci
CS101 - Exploring Circuit Simulation Tools: Online & Offline
CS101++ - What Are Logic Gates?
zhlédnutí 1,7KPřed 3 měsíci
CS101 - What Are Logic Gates?
C++ Weekly - Ep 414 - C++26's Placeholder Variables With No Name
zhlédnutí 11KPřed 3 měsíci
C Weekly - Ep 414 - C 26's Placeholder Variables With No Name
CS101++ - What Are Nibbles, Bits, Bytes and Words
zhlédnutí 2,3KPřed 3 měsíci
CS101 - What Are Nibbles, Bits, Bytes and Words
CS101++ - What Are Binary, Hexadecimal, Octal and Decimal?
zhlédnutí 1,5KPřed 3 měsíci
CS101 - What Are Binary, Hexadecimal, Octal and Decimal?
C++ Weekly - Ep 413 - (2x Faster!) What are Unity Builds (And How They Help)
zhlédnutí 7KPřed 3 měsíci
C Weekly - Ep 413 - (2x Faster!) What are Unity Builds (And How They Help)

Komentáře

  • @TheRobbix1206
    @TheRobbix1206 Před 57 minutami

    I think I would have use the capacity has the common field instead of the size because if for example you modify the length of your string a lot between let say 12 and 20 characters your solution force you to allocate deallocate each time you cross the 16 byte boundary. Whereas the capacity can stay at ~20 while your size can move around as it want. To use capacity instead we can say that size() = capacity when capacity < 16 else size and capacity() = max(16,capacity)

  • @ChandPriyankara-xu7hw
    @ChandPriyankara-xu7hw Před hodinou

    I compared aarch64 binaries with x86 abidiff, it just empty.

  • @FedericoPekin
    @FedericoPekin Před 5 hodinami

    awesome one!

  • @BartTrojanowski
    @BartTrojanowski Před 18 hodinami

    (++i)++;

  • @hwstar9416
    @hwstar9416 Před 20 hodinami

    honestly I'd rather if small string was a different type, maybe something like: small_string<10> str;

    • @ohwow2074
      @ohwow2074 Před 15 hodinami

      I don't know why they didn't choose to do that in the first place. Just let the user specify the size of the small buffer based on their needs. Now we're limited to a 16 byte buffer.

  • @UsernameUsername0000

    Isn’t std::size_t in <cstddef> not <cstdint>?

  • @andreasnilsson4300

    It is a shame that we had to wait 26-11=15 years for this feature

  • @garyp.7501
    @garyp.7501 Před dnem

    To pack this object into something even smaller in space you could use a bit field for the m_size, and while you can't allocate a string that is unsigned int64, you can allocate a unsigned int63. And use a bit at either end to indicate whether the space was allocated on the heap or using your m_small field of your other union. There of course is a minimal overhead of looking at those bit fields vs a bool or the int, but this is a thing that maps doing red/black do.

  • @pierrecolin6376
    @pierrecolin6376 Před dnem

    Is std::launder necessary for unions? I know the answer is no when the data members are active only once in the lifetime of the union, but this is not the case here.

  • @Xilefian
    @Xilefian Před dnem

    A good exercise is implementing small object optimised vector<bool>

  • @wChris_
    @wChris_ Před dnem

    Or just (ab)use std::basic_string<> for arrays with small object size optimizations.

  • @mjKlaim
    @mjKlaim Před dnem

    I would have made `is_small_storage()` a function which returns either `m_size < ` an arbitrary constant or the result of `m_size < sizeof(small_storage)` (so no additional storage needed for the bool). In several functions we would then need to re-evaluate this but I think it's worth it as it takes less space.

    • @antonpieper
      @antonpieper Před dnem

      Also, a "problem" with this and the video version is that the assignment operator would need to deallocate the memory if you assign a small string to a previously large string, because you would loose the pointer location

    • @mjKlaim
      @mjKlaim Před dnem

      @@antonpieper Yes the check has to be done for any of the modifying operations I guess.

    • @Mozartenhimer
      @Mozartenhimer Před dnem

      I think the real optimization would be just to make the most significant bit of the size a flag

    • @mjKlaim
      @mjKlaim Před dnem

      @@Mozartenhimer Doesnt that reduce the max size of the container? It's an undefined integer type so all the bits are used.

    • @Mozartenhimer
      @Mozartenhimer Před dnem

      @@mjKlaim I don't think you'll miss that 9.2 exabytes.

  • @PaulMetalhero
    @PaulMetalhero Před dnem

    Would love to see a std::variant version

  • @user-cy1rm5vb7i
    @user-cy1rm5vb7i Před dnem

    btw, offtopic question: since you really shouldn't store a function address in a void pointer, it's recommended to use a dummy function pointer type instead. The question is: can you reliably store a method pointer into this dummy function pointer type? Or what can you use instead of a void pointer to store a method pointer? 🤔

  • @negidrums915
    @negidrums915 Před dnem

    constexpr is essentially a compile-time UB sanitizer😮

  • @Subdest
    @Subdest Před dnem

    Why Boolean needed to check if it is a small object? Size is present. Max size of small object also is known. I doubt that checking Boolean is much faster then checking if some value is less then a constant…

    • @hampus23
      @hampus23 Před dnem

      Well, if you shrink the heap allocated string you don't reallocate so that won't work but there are better ways to do this.

    • @hampus23
      @hampus23 Před dnem

      Raymond Chen has written a great post (Inside STL: The string) about this.

    • @garyp.7501
      @garyp.7501 Před dnem

      If the string is shrunk, ie a short string is put into a what was a long string, you'd have to be sure to deallocate the extra space. That might be surprising to some users. Ie, long string, ... allocate short string ... deallocate long string ... allocate again. Vs long string .. allocate short string, .... no deallocation long but not too long string ... also no reallocation

    • @user-cy1rm5vb7i
      @user-cy1rm5vb7i Před dnem

      size can be zero even if it's a heap-allocated string. But capacity does reflect it's nature tho, you can use that, as long as heap allocated capacity is always larger than the max small string capacity

  • @user-cy1rm5vb7i
    @user-cy1rm5vb7i Před dnem

    I've just googled this topic today! PS: one could pack the small string even tighter, there's a way to use single byte for a size, but you'd store the max_small_string_capacity minus size instead. When the small string size equals the max capacity, the capacity minus size becomes zero and acts as a null terminator. 🤯

    • @higaski
      @higaski Před dnem

      That sounds like UB, given that the compiler is free to add padding to its liking.

    • @garyp.7501
      @garyp.7501 Před dnem

      @@higaski This trick that @user-cy1m5vb71 uses, could be put into yet another union, and thus you'd know about the packing.

    • @user-cy1rm5vb7i
      @user-cy1rm5vb7i Před dnem

      struct string { struct s_large { char* data; // assuming it's a 64bit pointer uint64_t size; // maybe even some padding to add extra stack space // like char padding[8]; }; struct s_small { static constexpr max_capacity = sizeof(s_large); char data[sizeof(heap) - 1]; char max_capacity_minus_size; }; uint64_t capacity; union { s_large l; s_small s; } data; }; even if there's some alignment padding added to the members of the s_large, the s_small should still be fine

    • @UsernameUsername0000
      @UsernameUsername0000 Před dnem

      @@user-cy1rm5vb7i I don’t get this approach. Won’t requesting c_str for a small string not be guaranteed-null-terminated?

    • @BaardFigur
      @BaardFigur Před 22 hodinami

      @@higaskiit's not UB

  • @apenaswellignton
    @apenaswellignton Před dnem

    I think this has to be one of the coolest examples on how and why to use constexpr.

    • @patrixonon
      @patrixonon Před dnem

      Yep, i've been writing my own custom string class implementation and i had to debug such cases at runtime which take me quite some time to make it right, whereas constexpr simply allow us to see the problem at compile time, which is very useful.

  • @Key_Capz_
    @Key_Capz_ Před 2 dny

    Are there any books on c++26 yet?

  • @theo-dr2dz
    @theo-dr2dz Před 2 dny

    Instead of hiring Jason Turner for onsite training, you could also buy the book on move semantics by Nicolai Josuttis (probably spelled the name wrong). It covers all dark corners of move semantics in detail and I guess it is considerably cheaper. The usecase of std::move is that if the member data of Lifetime is not an int, but a pointer to dynamically allocated memory, std::move(l1) will cause the move constructor to be called instead of the copy constructor. The copy constructor will do a dynamic allocation and copy the data, the move constructor will simply copy the pointer. You will still have 2 objects (one moved from, one moved to) but not an allocation and not a memcpy. That is the benefit of std::move. In the case he demonstrated here, you don't want move semantics, because that won't help you here. Here you want in-place construction, emplace() and the like. The lambda creates an object, elides the copy of the return value and so avoids the construction of a temporary. It's effectively an emplace.

  • @journeyman9162
    @journeyman9162 Před 3 dny

    This is great because it has the potential to decrease compile times significantly.

  • @caiovinicius5745
    @caiovinicius5745 Před 3 dny

    With expected is even worse! I'm using a static std::expected<Class, Err> to construct my object, and having a private constructor, but this blocks me from passing std::in_place + Args, as the constructor is private... How can I apply rvo in this case? will "return std::expected<Class, Err>(Class(args)); " work? I tried this and it called the move ctor...

  • @archer-reflection
    @archer-reflection Před 4 dny

    C++ will never die, because we all love it so much!

  • @MatthewWalker0
    @MatthewWalker0 Před 5 dny

    Can we thank circle for this?

  • @cristian-si1gb
    @cristian-si1gb Před 5 dny

    Careful tho, this implementation technically returns you an input_range, not a forwarding one, since the sequence is technically single pass only. The resulting view doesn't reflect that tho, algorithms you pass this into might break

  • @TechTutor429
    @TechTutor429 Před 6 dny

  • @sinom
    @sinom Před 6 dny

    On that note You can also do Param...[2] To get the type at index 2

  • @epiphaeny
    @epiphaeny Před 7 dny

    Can you also index into the types of the parameter pack and make some compile time checks there? E.g. std::is_same_v<int, Param...[3]> ?

    • @minirop
      @minirop Před 7 dny

      yes. args...[3] is the value and Args...[3] is the type and can be used with <type_traits>.

  • @ultimatesoup
    @ultimatesoup Před 8 dny

    This is really cool, but i dont see it being very useful in well designed code.

  • @PedroOliveira-sl6nw

    I would guess that most people, even if they want to use that, they will not be moving their codebase to C++26 until C++29 or later are released, because companies don't usually make this type of jump as freely...

    • @Spartan322
      @Spartan322 Před 7 dny

      Even with C++23 finished, because clang and gcc haven't finished their module implementations, (and iirc clang's concepts [least on Mac] can still produce ICEs, I know at least Apple's clang still hates some requires clauses, they simply don't work) most folks are still stuck on C++17 for universal support. I really hope the delay in finishing modules and properly functioning concepts doesn't delay development and adoption.

  • @Spirrwell
    @Spirrwell Před 8 dny

    FINALLY!

  • @VladykaVladykov
    @VladykaVladykov Před 8 dny

    Одна из главных вещей, которые я ожидаю в c++26

  • @sledgex9
    @sledgex9 Před 8 dny

    What happens if the parameter pack has only two elements and you try to access the 3rd elelement? Is it a no-op? Is it a compiler error? Can you test for at compile time so you enable a different code path in the template body?

    • @testtest-qm7cj
      @testtest-qm7cj Před 8 dny

      if constexpr (sizeof...(T) > some_constant_expression) { // do your thing }

    • @sledgex9
      @sledgex9 Před 7 dny

      @@testtest-qm7cj Thanks. So I assume from your answer: a) That there will be a compile time error, b) You can check for it in compile time and decide a different code path.

    • @testtest-qm7cj
      @testtest-qm7cj Před 7 dny

      @@sledgex9 a) yes, a compile time error is issued. b) yes, either you do what I showed above in the function body, or add another "requires-clause" to help your compiler. For example, extending Jason's code in the video, "requires (count>0) && ( count <= sizeof...(Param) )" would generate much nicer compile time error message when you try to access an out-of-bound element. By the way, "sizeof...(T)" is C++11, "if contexpr()" is C++17, and "requires ()" is C++20. You can test all these today.

    • @sledgex9
      @sledgex9 Před 7 dny

      @@testtest-qm7cj oh, so the only thing missing was a way to index into an item directly, which they will add in C++20.

  • @corndogblue7
    @corndogblue7 Před 8 dny

    I think you can also unpack into a tuple and then use get<n>(tuple) to access it yeah?

  • @DART2WADER
    @DART2WADER Před 8 dny

    Amazing innovation, now I write it with my hands and cunning overload operators.

  • @AminAramoon
    @AminAramoon Před 8 dny

    very cool

  • @vickoza1
    @vickoza1 Před 8 dny

    Does C++26 have ranges parameter pack support?

  • @amr3162
    @amr3162 Před 8 dny

    that params...[index] syntax is ugly. C++ honestly needs a new fresh coat of paint with better defaults, it's a beautiful and powerful language. just a bit ugly

    • @anon8510
      @anon8510 Před 8 dny

      well, is it beautiful or ugly?

    • @ohwow2074
      @ohwow2074 Před 8 dny

      It makes sense to me. It looks good.

    • @sephirostoy
      @sephirostoy Před 8 dny

      auto p = co_get<2>(params...);

    • @wojtekburzynski654
      @wojtekburzynski654 Před 8 dny

      If cppfront become production ready and catch on...

    • @Spartan322
      @Spartan322 Před 7 dny

      it makes perfect sense given that we use ... for varadic behavior already, and that was a C thing first, and some other languages do that.

  • @fcolecumberri
    @fcolecumberri Před 8 dny

    Considering that variadic templates came at C++14 (I think, haven't checked), one would assume this should have been added years ago.

    • @justdoityourself7134
      @justdoityourself7134 Před 8 dny

      Better late than never, but yes, very much so.

    • @AtomicAndi
      @AtomicAndi Před 8 dny

      yeah, made me mad every time because the compiler has the list, but lets you not use it

    • @Spartan322
      @Spartan322 Před 7 dny

      Variadic templates was a C++11 feature. I don't think C++14 did anything to even mess with them.

  • @milasudril
    @milasudril Před 8 dny

    C++26 will be great. I wonder how long it takes for it to be deployed.

    • @gregthemadmonk
      @gregthemadmonk Před 8 dny

      As stated, in the video, it's already in Clang (but not in release afaik)

    • @jwadaow
      @jwadaow Před 8 dny

      ​@@gregthemadmonkThis feature is in clang. Not necessarily further fratures of the nee standard.

    • @sinom
      @sinom Před 6 dny

      For C++26 to actually be mostly fully implemented will probably at least take until mid to late 2027. The thing currently that looks like it might be the most complex is reflection

  • @LogicEu
    @LogicEu Před 8 dny

    Very very nice... Is there a way of checking if the third parameter exists, though? What would happen if the third parameter doesn't exist? Compile time error, warning, UB??

    • @unluckyaf7673
      @unluckyaf7673 Před 8 dny

      Most probably a compile time error because the object doesn't exist

    • @testtest-qm7cj
      @testtest-qm7cj Před 8 dny

      @@unluckyaf7673 You can always use sizeof...(T) to test, which is a C++11 feature.

    • @sinom
      @sinom Před 6 dny

      I just tried it. It gives a really nice error: Error: invalid index 3 for pack params of size 3 return params...[3]; And it has an arrow to the "params" Then it also give stage a "note": note: in instantiation of function template specialization "func<int, const char*, int> requested here: auto var = func(1,"test", 2);

  • @mjKlaim
    @mjKlaim Před 8 dny

    Good, Now we need p1061 and P3115 and maybe P2994 and then maybe, just maybe, my hair will thank me for stopping puling it.

  • @oschonrock
    @oschonrock Před 8 dny

    yeah!..... for the longest time..

  • @franciscogerardohernandezr4788

    It feels like the input of a matlab function, but with the zero abstraction cost of c++. Awesome.

  • @Tyranisaur
    @Tyranisaur Před 8 dny

    Hey look, something with compile time bounds checking :D

    • @taw3e8
      @taw3e8 Před 8 dny

      Nice one :p

    • @aniketbisht2823
      @aniketbisht2823 Před 8 dny

      Constexpr context already gives you that (and more) guarantee(s).

  • @LucasGalfaso
    @LucasGalfaso Před 8 dny

    Well, another way would be to write this as ``` template<typename... Param> void func(Param... param) { std::get<2>(std::tie(param...)) = 42; } ```

    • @BaardFigur
      @BaardFigur Před 8 dny

      Wouldn't that allocate a large structure to store the references for the std::tie-object. params...[2] is probably far more efficient

    • @X_Baron
      @X_Baron Před 8 dny

      @@BaardFigur Clang optimizes it away. The outputs are identical.

    • @bloodgain
      @bloodgain Před 8 dny

      @@X_Baron And this is why we don't worry about things like this until they _need_ optimization. The compiler is usually already able to write better code than you will most of the time, even more so if you help it out with good basic practices like liberal use of const(expr). Be aware of things like C++ being row-major instead of column-major, but don't waste time frobnicating every bit of code until you've profiled it.

    • @AllCombo
      @AllCombo Před 7 dny

      great

  • @avramlevitter6150
    @avramlevitter6150 Před 8 dny

    One of the other ways you could do it prior to C++26 is by using std::tie to get references to the parameters and then using std::get<i>(tuple).

    • @cristian-si1gb
      @cristian-si1gb Před 8 dny

      Or std::forward_as_tuple if you need to ref qualifiers

  • @Erarnitox
    @Erarnitox Před 9 dny

    at 8:00 wouldn't return std::string(b?"Hello":"World"); also work? and it would be easier to read/write I think.

  • @caiovinicius7970
    @caiovinicius7970 Před 9 dny

    to avoid padded warnings you can introduce "char padding" members in your struct, to fill the gaps. this also allow for more easy knowing of were you can put new members in this struct wo breaking the alignment

  • @andrewneagle3124
    @andrewneagle3124 Před 10 dny

    Thanks for the heads up...problem solved