简体   繁体   中英

efficient way to search in `QMap<QString, ...>` using `QStringView`

I have a QVariantMap , which is an alias for QMap<QString, QVariant> . And I have a function which takes QStringView key as argument. I want to search a value in the map by the key.

QVariantMap map;
QStringView key;
QVariant v = map.value(key);

But the third line does not compile. Of course I could convert the string view to QString but this means one extra memory allocation. Is there any way around this which avoids the unnecessary allocation? How to lookup the value by just the string view?

there is no other solution,

  1. change the keys type to QStringView or
  2. QVariant v = map.value(key.toString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM