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. Member function empty() missing in some containers

Member function empty() missing in some containers

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 776 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.
  • B Offline
    B Offline
    bobhairgrove
    wrote on last edited by
    #1

    QList<> has empty(); QString and QByteArray do not. This makes it difficult to write portable code where these containers are actually typedef'd as either QString or std::string, QByteArray or std::vector<char> depending on whether or not the program is using Qt.

    Of course, we can use size(), but this is sometimes not very efficient if there is a lot of data in a vector or string. Scott Meyers, for example, recommends calling empty() if we don't need (or want) to know the actual size of a container's data.

    Would this break a lot of existing code if Qt added empty() to these containers?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bobhairgrove
      wrote on last edited by
      #2

      I saw that QVector also has empty(), and it also guarantees that its elements are adjacent in memory. I will use it to replace std::vector.

      1 Reply Last reply
      0

      • Login

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