Hacker News new | ask | show | jobs
by jeorgun 4068 days ago
Maybe I'm missing something, but why is it crucial that you hold on to a reference to the contents of the vector, and not the vector itself? Because, to me, the obvious "C++ way" to do it would be something like

    struct FieldInfo {
      //
      const std::vector<ast::Attribute>& attrs;
    }
2 comments

Well, if the object that owns the vector is destroyed then that reference will go dangling. The compiler can't (soundly) check this.
That operates under the assumption that no FieldInfo will be accessible after the original vector is deallocated, and similarly requires auditing to ensure this property holds (while making no guarantees about the future).