C++ Weekly - Ep 431 - CTAD for NTTP
HTML-код
- Опубликовано: 2 июн 2024
- ☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟
Upcoming Workshop: Understanding Object Lifetime, C++ On Sea, July 2, 2024
► cpponsea.uk/2024/sessions/und...
Upcoming Workshop: C++ Best Practices, NDC TechTown, Sept 9-10, 2024
► ndctechtown.com/workshops/c-b...
Upcoming Workshop: Applied constexpr: The Power of Compile-Time Resources, C++ Under The Sea, October 10, 2024
► cppunderthesea.nl/workshops/
Episode details: github.com/lefticus/cpp_weekl...
T-SHIRTS AVAILABLE!
► The best C++ T-Shirts anywhere! my-store-d16a2f.creator-sprin...
WANT MORE JASON?
► My Training Classes: emptycrate.com/training.html
► Follow me on twitter: / lefticus
SUPPORT THE CHANNEL
► Patreon: / lefticus
► Github Sponsors: github.com/sponsors/lefticus
► Paypal Donation: www.paypal.com/donate/?hosted...
GET INVOLVED
► Video Idea List: github.com/lefticus/cpp_weekl...
JASON'S BOOKS
► C++23 Best Practices
Leanpub Ebook: leanpub.com/cpp23_best_practi...
► 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/objectlifetimepuz...
► Object Lifetime Puzzlers Book 2
Amazon Paperback: amzn.to/3whdUDU
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Object Lifetime Puzzlers Book 3
Leanpub Ebook: leanpub.com/objectlifetimepuz...
► Copy and Reference Puzzlers Book 1
Amazon Paperback: amzn.to/3g7ZVb9
Leanpub Ebook: leanpub.com/copyandreferencep...
► Copy and Reference Puzzlers Book 2
Amazon Paperback: amzn.to/3X1LOIx
Leanpub Ebook: leanpub.com/copyandreferencep...
► Copy and Reference Puzzlers Book 3
Leanpub Ebook: leanpub.com/copyandreferencep...
► 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...
► C++ Best Practices Forkable Coding Standards - github.com/cpp-best-practices...
O'Reilly VIDEOS
► Inheritance and Polymorphism in C++ - www.oreilly.com/library/view/...
► Learning C++ Best Practices - www.oreilly.com/library/view/... Наука
Thanks for explaining all these concepts. I couldn't even find something related to NTTP when I did a quick Internet search. I also loved seeing the Demangler website. I didn't know this existed!
C++ committee on its way to design the most powerful compile-time metaprogramming facilities known to man(they saved typing 6 extra characters)
Nah I like this feature fr. I can find specific cases where this can be super helpful.
Thanks for the information and example
It seems to compile with gcc and MSVC, but not with clang
Reminds me of this gcc/clang extension with template string literal operator overloads. If I remember correctly it looks like this:
template
auto operator""_foo();
sml uses it for the state notation, for instance.
To invoke it, it's just "mystring"_foo or the like.
Maybe this can be expressed some other way in native c++ without the extension (which does work in any compiler worth using. MSVC is the only odd one out)
isn't this in the language already?
Having to specify template class types is a pain when you want to support std::vector with custom allocators. This becomes very trivial to do right now...
I wonder how the compiler and/or linker will handle a symbol name that's, say, a couple of megabytes long.
MSVC might truncate it. Or at least it used to...
sorry to be nit-picky but the second vector you defined is a vector of double, not float. for float you would need to define `1.f, 2.f` etc
Ok a bit of a miss-speak. In my head it was meant to be "a vector of floating-point values" (Yes I'm aware that floating point values are defaulted double in C and C++)
Is there a reason to use that instead of consteval?
templateauto get_value() { return x; }
VS
consteval auto get_value(int x) { return x; }
Is there a difference between those, besides syntax of the call?
I believe you can make either work for most contexts. It's a question of ergonomics, largely. Which do you prefer based on what you're trying to do at the moment.
That's some crazy shit for a c# developer 😅 I don't have an idea for what I could use this ...
Just think "how can I make more work happen at compile time" and this will eventually come up. Work done at compile time doesn't have to happen at runtime, and also it can influence the optimizer to do even *more* work at compile time.
What I do not understand is this. What is the benefit of passing arrays as template parameters as opposed to passing them as just "normal" parameters? Also: does this work with other types (strings, vectors, maps, etc.)?
Template parameters are guaranteed to be resolved at compile time, whereas normal parameters are usually dealt with at runtime.
Because an std::array is a template itself. eg you can have std::array and std::array which are different types. So if you want to pass them as "normal" parameters you'll have to explicitly write out their template arguments aka std::array and make multiple overloads of the function if you want to take in different kinds of std::array. That's a maintenance nightmare.
@@sledgex9 You are talking rubbish, because you can definitely put the template parameters of the array as a template parameters for your function:
template T get_value(std::array a) { return a[1]; }
@@ysakhno Notice that you had to explicitly mention/enumerate the template arguments of your function parameter.
An application I could think of would be in writing rank-independent numerical code using template metaprogramming, something akin to what Todd Veldhuizen did with Blitz++. The rank of the passed-in array would be the rank of the resulting tensor and its values the length of each dimension.
C++ has gotten too complicated. There I said it. The story used to be that there was a simple, elegant programming language trying to escape from all the backward compatibility but I feel we've gone way beyond that. I am interested to see where Herb Sutter's CPP2 takes us.
"trying to escape from all the backward compatibility" I may have come to C++ too late, but was that ever the story? Wasn't C++ main selling point its huge backwards compatibility with C?
There are things that are complicated because of non technical reasons, but this is pure luddite talk, this is one of the things that you'd still be able to to in CPP2....
@@gregthemadmonk Sure but it's the backwards compatibility of later versions of C++ with earlier versions of C++ that is the bigger burden. There are now multiple ways to do any one thing but only one of those ways is considered the "good" way.
@@snbv5real CPP2 in is pure mode where old C++ constructs aren't accepted is designed to be the "much smaller and cleaner language struggling to get out" (Stroustrup). Wanting this is not Luddite talk but forward looking IMHO.
@@PaulTopping1 I'm not sure it is such a bad thing, to be completely honest. It allows developers not to rewrite libraries (including the standard library) every time a new way to do a thing drops. Sure, it is a burden to know all of the ways to do the same stuff, but a) it is, in my opinion, a fair trade for being able to use older libraries and not being stuck in dependency incompatibility hell and b) the "best" way to do a thing is usually the most recent one, I don't see much confusion arising here aside from people intentionally confusing themselves
So basically a foot-gun.
Interesting. How so?
This is very difficult to use wrong
That's just about the most horrible name mangling scheme I've seen. Also, I kind of feel like CTAD is dumb in this particular context. It would make more sense if there were some container types that were more built-in to the language, but that's not really the C++ way. But this is one of the many reasons I've been implementing my own language.