Date: Thu, 9 Jul 2020 16:11:00 -0700
>
> Okay. Now, instead of writing const unordered_set<string> myset ({
> "a"s, "b"s, "c"s, ...});
> you can write const unordered_set<string> myset ({ string("a"),
> string("b"), string("c"), ...});
> and you should hopefully see the same decrease in compilation time. In
> other words,
Using strings directly doesn't seem to help (the compilation goes on
forever). I tried with both std=c++11 & std=c++14, and there was no
difference.
> since it looks like the string constructor overloads for the
> initializer_list are a cause of slowdown,
> make sure the initializer_list contains strings, instead of having it
> convert strings. The literal is just
> one way to do that, explicit string initializers are another
>
> > 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.
>
> You can use an unordered_set with a custom comparator. That way you
> can get the comparison
> to compare the data, not the pointers.
Thanks, this sounds like a good workaround.
>
> I'm not quite convinced this is on-topic any more. :) This is not a
> "how to program correctly in C++" forum.
I agree :) (an answer on quora led me to incorrectly assume that this
was a list for discussing C++ stdlib related questions (since my
problem stemmed from a class i stdlib), whereas this list is more for
discussion around the C++ standard as such?)
Anyway thanks for the pointers (no pun intended), and your time.
-mandeep
> Okay. Now, instead of writing const unordered_set<string> myset ({
> "a"s, "b"s, "c"s, ...});
> you can write const unordered_set<string> myset ({ string("a"),
> string("b"), string("c"), ...});
> and you should hopefully see the same decrease in compilation time. In
> other words,
Using strings directly doesn't seem to help (the compilation goes on
forever). I tried with both std=c++11 & std=c++14, and there was no
difference.
> since it looks like the string constructor overloads for the
> initializer_list are a cause of slowdown,
> make sure the initializer_list contains strings, instead of having it
> convert strings. The literal is just
> one way to do that, explicit string initializers are another
>
> > 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.
>
> You can use an unordered_set with a custom comparator. That way you
> can get the comparison
> to compare the data, not the pointers.
Thanks, this sounds like a good workaround.
>
> I'm not quite convinced this is on-topic any more. :) This is not a
> "how to program correctly in C++" forum.
I agree :) (an answer on quora led me to incorrectly assume that this
was a list for discussing C++ stdlib related questions (since my
problem stemmed from a class i stdlib), whereas this list is more for
discussion around the C++ standard as such?)
Anyway thanks for the pointers (no pun intended), and your time.
-mandeep
Received on 2020-07-09 18:14:26