2424#include < sanitizer/asan_interface.h> // ASAN
2525#endif
2626
27- #include < algorithm> // `std::transform`
28- #include < cstdio> // `std::printf`
29- #include < cstring> // `std::memcpy`
30- #include < iterator> // `std::distance`
31- #include < memory> // `std::allocator`
32- #include < random> // `std::random_device`
33- #include < sstream> // `std::ostringstream`
34- #include < vector> // `std::vector`
27+ #include < algorithm> // `std::transform`
28+ #include < cstdio> // `std::printf`
29+ #include < cstring> // `std::memcpy`
30+ #include < iterator> // `std::distance`
31+ #include < map> // `std::map`
32+ #include < memory> // `std::allocator`
33+ #include < random> // `std::random_device`
34+ #include < sstream> // `std::ostringstream`
35+ #include < unordered_map> // `std::unordered_map`
36+ #include < vector> // `std::vector`
3537
3638#include < string> // Baseline
3739#include < string_view> // Baseline
@@ -58,6 +60,14 @@ template class std::basic_string<char>;
5860template class sz ::basic_string<char >;
5961template class sz ::basic_charset<char >;
6062
63+ template class std ::vector<sz::string>;
64+ template class std ::map<sz::string, int >;
65+ template class std ::unordered_map<sz::string, int >;
66+
67+ template class std ::vector<sz::string_view>;
68+ template class std ::map<sz::string_view, int >;
69+ template class std ::unordered_map<sz::string_view, int >;
70+
6171/* *
6272 * @brief Several string processing operations rely on computing integer logarithms.
6373 * Failures in such operations will result in wrong `resize` outcomes and heap corruption.
@@ -394,6 +404,10 @@ static void test_stl_compatibility_for_reads() {
394404 assert (str (" 12341234" ) <= str (" 12341234" ));
395405 assert (str (" 12341234" ) > str (" 12241224" ));
396406 assert (str (" 12341234" ) < str (" 13241324" ));
407+ assert (str (" 0123456789012345678901234567890123456789012345678901234567890123" ) ==
408+ str (" 0123456789012345678901234567890123456789012345678901234567890123" ));
409+ assert (str (" 0123456789012345678901234567890123456789012345678901234567890123" ) !=
410+ str (" 0223456789012345678901234567890123456789012345678901234567890123" ));
397411
398412 // Comparisons.
399413 assert (str (" a" ) != str (" b" ));
@@ -1489,6 +1503,21 @@ static void test_sequence_algorithms() {
14891503 }
14901504}
14911505
1506+ /* *
1507+ * @brief Tests constructing STL containers with StringZilla strings.
1508+ */
1509+ static void test_stl_containers () {
1510+ std::map<sz::string, int > sorted_words_sz;
1511+ std::unordered_map<sz::string, int > words_sz;
1512+ assert (sorted_words_sz.empty ());
1513+ assert (words_sz.empty ());
1514+
1515+ std::map<std::string, int , sz::string_view_less> sorted_words_stl;
1516+ std::unordered_map<std::string, int , sz::string_view_hash, sz::string_view_equal_to> words_stl;
1517+ assert (sorted_words_stl.empty ());
1518+ assert (words_stl.empty ());
1519+ }
1520+
14921521int main (int argc, char const **argv) {
14931522
14941523 // Let's greet the user nicely
@@ -1539,6 +1568,7 @@ int main(int argc, char const **argv) {
15391568
15401569 // Sequences of strings
15411570 test_sequence_algorithms ();
1571+ test_stl_containers ();
15421572
15431573 std::printf (" All tests passed... Unbelievable!\n " );
15441574 return 0 ;
0 commit comments