std::vector continuity

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lynn

    #1

    std::vector continuity

    Are std::vector items guaranteed to be continuous ?

    For instance, if I have a "std::vecto r <char> text".
    If I get a pointer "char *p = & text [0];", can use the
    pointer to work thru the limits of the vector ?

    Thanks,
    Lynn McGuire


  • Ron Natalie

    #2
    Re: std::vector continuity

    Lynn wrote:[color=blue]
    > Are std::vector items guaranteed to be continuous ?
    >
    > For instance, if I have a "std::vecto r <char> text".
    > If I get a pointer "char *p = & text [0];", can use the
    > pointer to work thru the limits of the vector ?[/color]
    Yes, until you cause the capacity of the vector to change.

    Comment

    • Rolf Magnus

      #3
      Re: std::vector continuity

      Lynn wrote:
      [color=blue]
      > Are std::vector items guaranteed to be continuous ?[/color]

      Yes. Well, they officially weren't before the 2003 version of the C++
      standard, but there seems to be no known implementation that didn't store
      the data continuously.
      [color=blue]
      > For instance, if I have a "std::vecto r <char> text".
      > If I get a pointer "char *p = & text [0];", can use the
      > pointer to work thru the limits of the vector ?[/color]

      Yes.

      Comment

      Working...