2

I have a long string of urlParams, I would like to check if the keys in my string exist in the hashMap, one option would be to use std::string.substr to extract the keys from the source string and check if they are in the hashmap, however, I would like to avoid creating new objects.

Is there a way to check if my key in the hashmap by providing the source string, and the position of my key in that source?

I use a simple hashmap std::map<std::string, std::string>, but I can change it if you think it can help

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216

1 Answers1

4

Solution to your problem is described here: Use of string_view for map lookup.

You want to create simply string_view (by source string and position, also by the length), and use it for lookup. No new objects created.

sandyre
  • 175
  • 2
  • 9