← Back to context

Comment by purplesyringa

1 day ago

> Lifetime parameters aren't necessary, lifetime contracts may be implemented in a different and much easier way. This may be expressed in form of a function attribute, which may be calculated via constexpr code.

Wouldn't that just be slightly different syntax for the same idea? If you want to represent relationships like "the pointer in the field Struct::field_name within this argument is linked with the lifetime of the returned pointer" and you want them to be reusable across functions and contexts, isn't the most obvious way to write that a variant of

    struct Struct<'a> {
        char *'a field_name;
    };

    char *'a f<'a>(Struct<'a>& struct);

?

Using tags like 'a may work, but it's not flexible in templated code. A better approach is to allow calculating such tags in compilation time. But in such way you don't even need named tags, you can just use pairs of integers, like reference #n of param #m.