Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-14545

QMap setDefault functionality

    XMLWordPrintable

Details

    Description

      The QMap class already has the functionality to return a default value if an item isn't found at the specified key. This is found in

      const T QMap::value ( const Key & key, const T & defaultValue ) const

      This functionality is very useful, but I often find with keyed collections like a map, that I would like to insert an item with some default value at a given key. I usually implement some sort of getDefault() function. This could be defined as such:

      /** Gets a value associated with a key from the QMap.  If no entry matching the key is found, the default value is inserted and returned
        * @param  key - The key with which to look up the item
        * @param  defaultValue - The default value to insert if the associated key is not found in the map
        * @return A reference to the value associated with the given key.  If there was no value at the key, this will be a reference to the newly added default value
        */
      const T& QMap::getDefault( const Key& key, const T& defaultValue );
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            dusktreader Tucker Beck
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes