This is one of those features I love I can use and I hate the confusing way it is written.
@czarsonxd2093Ай бұрын
had no clue about this
@AndiAbrudanАй бұрын
Wow, this is more useful than just the casting part. I find working with the expansion operator very cumbersome; maybe because I haven't studied all the rules. But with this syntax, you're moving the expansion at the top of the lambda, and you're free to use `strlike` as a single object inside the body. Awesome video!
@AtomicAndiАй бұрын
Thanks for pointing that out. The video was maybe not so awesome after all, because I missed the point about the expansion being kind of outside
@majohimeАй бұрын
If only I could find more cool variadic templates/fold expressions related stuff like this
@cppweekly23 күн бұрын
Upcoming talk at CppCon 2024 will dig into some of this stuff.
Ай бұрын
This is madness!
@BenjaminWheeler0510Ай бұрын
I am lost on all the ellipses unfortunately :( which videos do you cover those on again?
@UsernameUsername0000Ай бұрын
Look up parameter pack and then fold expressions.
@ohwow2074Ай бұрын
It's crazy. I have never heard of this particular use of parameter pack expansion. I guess it'll come in handy.
@Rosen2221Ай бұрын
Literally wrote a subsystem for transporting some version information between client and server, which had almost the exact same function and problem as this video. The function in question was just merging single tokens (from constexpr defines, strings at hand in the version constructing class and other string_view like identifier). WIth the lambda capture we can output a total_size from the single tokens (of whatever stringlike type) and create a new string with reserved size onto which to append
@N....Ай бұрын
Ahh ok, I see now what you were talking about, that is indeed simpler than the way I suggested, cool!
@ihatelhpАй бұрын
Surely there are reasons why the ... comes before the identifier initializer?
@abhinavk0929Ай бұрын
...iden is the syntax to inroduce a parameter pack with the name "iden". So 'strlike' is a pack that consists of string_views into the parameter strings.
@PedroOliveira-sl6nwАй бұрын
What about lifetime of string views? In this simple case it's okay. But imagine that you return the lambda (instead of void function).
@cppweekly23 күн бұрын
Yes, that's a potential problem. kzbin.info/www/bejne/mYbZlaeCia-Ym8U
@badassopenpollingАй бұрын
nice!
@SylphDSАй бұрын
I feel like this is the kind of code you can only read for a about a week after you write it, and then if you read it again at any point after that you get instantly lost in the folding expressions. They are not very intuitive.
@diablo384Ай бұрын
Does the string_view{...input} make another copy in that lambda function? I can't get it.
@cppweekly23 күн бұрын
string_view is never a copy, so it's just creating a view (pointer + length) for each string-like thing passed in. This is not 0 cost, necessarily, but it is very low cost. It might incur some strlen calls sometimes, but otherwise should just be copying 2 pointer-sized things per element.
@troylowry4239Ай бұрын
Wtf is going on in the comments
@majohimeАй бұрын
At least no bots spouting slurs, still kinda weird
@RomanOrekhovАй бұрын
probably the word "captures" triggered the bots
@AtomicAndiАй бұрын
Weird example. I'd rather have work_with_stringlike take everything by stringview. How would the code look then?
@anon_y_mousseАй бұрын
It's this kind of garbage syntax why I've been working on my own language and the issue with strings is why the default string type in my language *is* a string view.
@sigasigasigaАй бұрын
std::size be like "oh yeah why am i needed anyway"
@N....Ай бұрын
The funny thing about slideware is its selective memory since it's trying to be relevant in other contexts too