how many layer the vector can be?

Discussion in 'C++' started by kathy, Apr 15, 2008.

  1. kathy

    kathy Guest

    I try to use:

    std::vector <std::vector <std::vector <int>>>;

    But it seems not work.

    how many layer the vector can be?

    for example:

    std::vector <std::vector <std::vector <int>>> v1;
    std::vector <std::vector <int>> v2;

    v1.resize(2);
    v1[0].resize(2);
    v1[0][0].resize(2);
    v1[0][0][0] = 1;//wrong

    v2.resize(2);
    v2[0].resize(2);
    v2[0][0] = 1;//OK
    kathy, Apr 15, 2008
    #1
    1. Advertising

  2. kathy

    Guest

    On Apr 15, 10:31 am, kathy <> wrote:
    > I try to use:
    >
    > std::vector <std::vector <std::vector <int>>>;


    You need to put spaces between > characters. Otherwise the compiler
    parser will take two of them together to be the right shift operator:
    >>


    Better yet, use typedefs to make this code more readable:

    typedef vector<int> SomeType;
    typedef vector<SomeType> SomeName;
    typedef vector<SomeName> SomeOtherName;

    Ali
    , Apr 15, 2008
    #2
    1. Advertising

  3. kathy

    Joe Greer Guest

    kathy <> wrote in news:aa8083cf-1554-40fc-b13f-
    :

    > I try to use:
    >
    > std::vector <std::vector <std::vector <int>>>;
    >
    > But it seems not work.
    >
    > how many layer the vector can be?


    I am sure there is some compiler limit, but mostly it will depend upon how
    many you enter in your declaration.
    >
    > for example:
    >
    > std::vector <std::vector <std::vector <int>>> v1;



    > std::vector <std::vector <int>> v2;
    >
    > v1.resize(2);
    > v1[0].resize(2);
    > v1[0][0].resize(2);
    > v1[0][0][0] = 1;//wrong


    v1 is a vector of vectors of vectors of int
    v1[0] is a vector of vectors of int
    v1[0][0] is a vector of int
    v1[0][0][0] is not valid.

    hope that helps,
    joe
    Joe Greer, Apr 15, 2008
    #3
  4. kathy

    red floyd Guest

    Joe Greer wrote:
    > kathy <> wrote in news:aa8083cf-1554-40fc-b13f-
    > :
    >
    >> I try to use:
    >>
    >> std::vector <std::vector <std::vector <int>>>;
    >>
    >> But it seems not work.
    >>
    >> how many layer the vector can be?

    >
    > I am sure there is some compiler limit, but mostly it will depend upon how
    > many you enter in your declaration.
    >> for example:
    >>
    >> std::vector <std::vector <std::vector <int>>> v1;

    >
    >
    >> std::vector <std::vector <int>> v2;
    >>
    >> v1.resize(2);
    >> v1[0].resize(2);
    >> v1[0][0].resize(2);
    >> v1[0][0][0] = 1;//wrong

    >
    > v1 is a vector of vectors of vectors of int
    > v1[0] is a vector of vectors of int
    > v1[0][0] is a vector of int
    > v1[0][0][0] is not valid.


    v1[0][0][0] is a reference to an int.
    red floyd, Apr 15, 2008
    #4
  5. kathy

    kathy Guest


    > v1 is a vector of vectors of vectors of int
    > v1[0] is a vector of vectors of int
    > v1[0][0] is a vector of int
    > v1[0][0][0] is not valid.
    >
    > hope that helps,
    > joe


    I believe the v1[0][0][0] IS valid. It is integer.
    kathy, Apr 15, 2008
    #5
  6. kathy

    Joe Greer Guest

    red floyd <> wrote in
    news:1r6Nj.9406$:

    > Joe Greer wrote:
    >> kathy <> wrote in news:aa8083cf-1554-40fc-b13f-
    >> :
    >>
    >>> I try to use:
    >>>
    >>> std::vector <std::vector <std::vector <int>>>;
    >>>
    >>> But it seems not work.
    >>>
    >>> how many layer the vector can be?

    >>
    >> I am sure there is some compiler limit, but mostly it will depend
    >> upon how many you enter in your declaration.
    >>> for example:
    >>>
    >>> std::vector <std::vector <std::vector <int>>> v1;

    >>
    >>
    >>> std::vector <std::vector <int>> v2;
    >>>
    >>> v1.resize(2);
    >>> v1[0].resize(2);
    >>> v1[0][0].resize(2);
    >>> v1[0][0][0] = 1;//wrong

    >>
    >> v1 is a vector of vectors of vectors of int
    >> v1[0] is a vector of vectors of int
    >> v1[0][0] is a vector of int
    >> v1[0][0][0] is not valid.

    >
    > v1[0][0][0] is a reference to an int.
    >


    True, my bad. sigh.

    joe
    Joe Greer, Apr 15, 2008
    #6
  7. kathy

    James Kanze Guest

    On 15 avr, 19:40, "Victor Bazarov" <> wrote:
    > kathy wrote:


    [...]
    > > how many layer the vector can be?


    > Many. The limitation should be documented in your compiler
    > manual.


    From a quality of implementation point of view, probably, but
    I'm not sure that the standard requires that the implementation
    limits be documented. In practice, the most I think you'll find
    is how deep templates can be nested. And since you don't know
    how deep the implementation of std::vector nests them already,
    that doesn't advance you much.

    If the error is due to template nesting, some compilers have
    options to increase it. (Early implementations of templates
    often made it artificially low, since the typical case was
    unintentional recursion, without a specialization to stop it. I
    think that these restrictions are being raised, because the only
    way to implement a loop in template metaprogramming is via such
    recursion.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Apr 15, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YzY3NjIyOA==?=

    do it in database layer or application layer

    =?Utf-8?B?YzY3NjIyOA==?=, Jan 26, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    424
    Karl Seguin [MVP]
    Jan 27, 2006
  2. et
    Replies:
    2
    Views:
    1,896
  3. dan
    Replies:
    25
    Views:
    1,321
    Uncle Bob (Robert C. Martin)
    Oct 28, 2003
  4. Dhananjay
    Replies:
    1
    Views:
    1,098
    sloan
    Dec 18, 2006
  5. Replies:
    8
    Views:
    1,896
    Csaba
    Feb 18, 2006
Loading...

Share This Page