Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. std::array or QVector
Forum Updated to NodeBB v4.3 + New Features

std::array or QVector

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sandro4912
    wrote on 11 Nov 2019, 18:26 last edited by
    #1

    In pure C++ it is now considered good practice to declare a Container with always a fixed size as std::array. I wonder how is it with using the QT Framework. From what i know theres no QArray So whats the solution here? Using QVector or std::array ?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Nov 2019, 18:28 last edited by
      #2

      Hi,

      It depends on your use case and features you seek. Qt containers are COW by default so cheap to copy for example.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • S Offline
        S Offline
        sandro4912
        wrote on 11 Nov 2019, 18:35 last edited by
        #3

        @SGaist said in std::array or QVector:

        COW

        Well im building a dungeon which is represented by 20 Rooms. In this case the dungeon is designed to only work with 20 Items because they get connected as a Dodekaeder.

        My functions to connect the Rooms as Dodekaeder only work for therefore for 20 Rooms.

        It would be nice to only allow containers to get passed to it with size of 20. If I would use QVector I have to atleast assert in the function that the size is correct. With std::array<Room *, 20> it would be cleaner the intend that only 20 is allowed.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fcarney
          wrote on 11 Nov 2019, 18:59 last edited by
          #4

          @sandro4912 said in std::array or QVector:

          In pure C++ it is now considered good practice to declare a Container with always a fixed size as std::array

          Who says this? Reference? This is highly dependent upon use case. std::vector is not any slower if you code correctly (for non-trivial use cases).

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 11 Nov 2019, 20:15 last edited by
            #5

            Then use std::array since it suites your needs.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            1/5

            11 Nov 2019, 18:26

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved