codeql-coding-standards icon indicating copy to clipboard operation
codeql-coding-standards copied to clipboard

How to overcome strictly weakly ordered for `sets` and `maps`

Open MFaisalZaki opened this issue 3 years ago • 0 comments

I have this code snippet

#include <iostream>
#include <string>
#include <set>
#include <map>

int main() {
    std::set<std::string> std_section_names;
	std_section_names.insert(".text");
	std_section_names.insert(".itext");
	
    // ---- 
	std::map<std::string, double> pe_attr = {
		{"instructionsCount", 0.0},
	};
    return 0;
}

Where I created a set of strings and a map with string to double in order to count frequency. However, the CTR57-CPP hits with this message

Comparator 'std::less<basic_string<char, char_traits<char>, allocator<char>>>' used on container or sorting algorithm that is not strictly weakly ordered 
```. 

I understand the issue very well, yet I don't know how to fix it properly.

MFaisalZaki avatar Aug 17 '22 10:08 MFaisalZaki