how many layer the vector can be?

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

    how many layer the vector can be?

    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



  • Victor Bazarov

    #2
    Re: how many layer the vector can be?

    kathy wrote:
    I try to use:
    >
    std::vector <std::vector <std::vector <int>>>;
    >
    But it seems not work.
    FAQ 5.8.
    how many layer the vector can be?
    Many. The limitation should be documented in your compiler
    manual.
    >
    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
    "Wrong"?
    >
    v2.resize(2);
    v2[0].resize(2);
    v2[0][0] = 1;//OK
    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • acehreli@gmail.com

      #3
      Re: how many layer the vector can be?

      On Apr 15, 10:31 am, kathy <yqin...@yahoo. comwrote:
      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<intSomeT ype;
      typedef vector<SomeType SomeName;
      typedef vector<SomeName SomeOtherName;

      Ali

      Comment

      • Joe Greer

        #4
        Re: how many layer the vector can be?

        kathy <yqin_99@yahoo. comwrote in news:aa8083cf-1554-40fc-b13f-
        32b96ae766da@z2 4g2000prf.googl egroups.com:
        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

        Comment

        • red floyd

          #5
          Re: how many layer the vector can be?

          Joe Greer wrote:
          kathy <yqin_99@yahoo. comwrote in news:aa8083cf-1554-40fc-b13f-
          32b96ae766da@z2 4g2000prf.googl egroups.com:
          >
          >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.

          Comment

          • Victor Bazarov

            #6
            Re: how many layer the vector can be?

            Joe Greer wrote:
            kathy <yqin_99@yahoo. comwrote in news:aa8083cf-1554-40fc-b13f-
            32b96ae766da@z2 4g2000prf.googl egroups.com:
            >
            >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.
            Why? If 'v1[0][0]' is a vector of int, then 'v1[0][0][0]' is an int.
            hope that helps,
            joe
            V
            --
            Please remove capital 'A's when replying by e-mail
            I do not respond to top-posted replies, please don't ask


            Comment

            • kathy

              #7
              Re: how many layer the vector can be?

              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.

              Comment

              • Joe Greer

                #8
                Re: how many layer the vector can be?

                red floyd <no.spam@here.d udewrote in
                news:1r6Nj.9406 $2g1.6763@nlpi0 68.nbdc.sbc.com :
                Joe Greer wrote:
                >kathy <yqin_99@yahoo. comwrote in news:aa8083cf-1554-40fc-b13f-
                >32b96ae766da@z2 4g2000prf.googl egroups.com:
                >>
                >>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

                Comment

                • James Kanze

                  #9
                  Re: how many layer the vector can be?

                  On 15 avr, 19:40, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
                  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:james.kan ze@gmail.com
                  Conseils en informatique orientée objet/
                  Beratung in objektorientier ter Datenverarbeitu ng
                  9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                  Comment

                  Working...