|
|
|
|
|
by kentonv
912 days ago
|
|
What's UB about it? Any temporary objects constructed during the evaluation of a statement live until the end of the statement. The standard is clear on that. > i think i’d prefer to require a value preserving the lifetime of the reader/view. in the cases that it may not be necessary, i'd prefer to lean on the optimiser to take care of it..! We'd all prefer APIs that cannot be used unsafely but realistically there's no magic the optimizer can do to make the problems with refcounting go away. You need to use a language like Rust to solve this. |
|
perhaps for values like this you’re fine. i think my point still stands about the reader of a built-in list/sequence type, surely?
and, not to sound facetious, that’s exactly what optimisers do :)
the c++ type system is more than capable about reasoning about lifetimes, the issue is that, with c++, it’s an optional part of the language. also, the lack of non-destructive moves. but to require both of those things in the language would require, essentially, the borrow checker in rust.