| 1 |
// { dg-do run { target c++11 } } |
| 2 |
|
| 3 |
// libstdc++/115285 |
| 4 |
|
| 5 |
#include <unordered_set> |
| 6 |
#include <string> |
| 7 |
#include <vector> |
| 8 |
|
| 9 |
#include <testsuite_hooks.h> |
| 10 |
|
| 11 |
class TrimmedStr : public std::string |
| 12 |
{ |
| 13 |
static std::string trim_str(std::string const &str) |
| 14 |
{ |
| 15 |
auto start = str.find_first_not_of(" \r\n\t"); |
| 16 |
|
| 17 |
return start == std::string::npos |
| 18 |
? str |
| 19 |
: str.substr(start, str.find_last_not_of(" \r\n\t") - start + 1); |
| 20 |
} |
| 21 |
|
| 22 |
public: |
| 23 |
TrimmedStr(std::string const &arg) |
| 24 |
: std::string{trim_str(arg)} {} |
| 25 |
TrimmedStr(char const *arg) |
| 26 |
: TrimmedStr{std::string{arg}} {} |
| 27 |
}; |
| 28 |
|
| 29 |
int main() |
| 30 |
{ |
| 31 |
std::unordered_set<TrimmedStr, std::hash<std::string>, std::equal_to<std::string>> |
| 32 |
set_from_initializer_list{ "foo", "bar", " foo ", " bar " }; |
| 33 |
|
| 34 |
VERIFY( set_from_initializer_list.size() == 2 ); |
| 35 |
|
| 36 |
std::vector<std::string> args{ "foo", "bar", " foo ", " bar " }; |
| 37 |
std::unordered_set<TrimmedStr, std::hash<std::string>, std::equal_to<std::string>> |
| 38 |
set_from_iterators; |
| 39 |
set_from_iterators.insert(args.begin(), args.end()); |
| 40 |
VERIFY( set_from_iterators.size() == 2 ); |
| 41 |
} |