C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: extremely long compile time with large number of string literals
From: Mandeep Sandhu (mandeepsandhu.chd_at_[hidden])
Date: 2020-07-09 17:43:52


> > $ g++ -std=c++11 -o string_udl_test string_udl_test.cc
> > string_udl_test.cc:7:38: error: unable to find string literal operator
> > ‘operator""s’ with ‘const char [2]’, ‘long unsigned int’ arguments
> > 7 | const unordered_set<string> myset ({ "a"s, "b"s, "c"s, });
>
> The literals require C++14 to work.

Oh, I might've confused it with
https://en.cppreference.com/w/cpp/language/user_literal

And indeed, using string literal greatly reduces the compilation time!

The set with 50K strings, now compiles in7 secs! Unfortunately, I'm
not sure if I can use c++14 in our project yet.

>
> Perhaps you need to use an unordered_set<const char*>.

I did that initially just to see how it affected compilation speed.
While, its much faster with "const char*" (I think it was. < secs for
compiling 50K literals), its not usable since I don't want to compare
the pointers but the pointed to data:

const unordered_set<const char*> myset ({ "a", "b", "c", });

string key {"a"};
myset.find(key.c_str()); // does not find "a"

This is why I was trying to use string instead.

-mandeep


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups