perf_collate.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #include <iostream>
  9. #include <string>
  10. #include <set>
  11. #include <boost/locale.hpp>
  12. using namespace std;
  13. using namespace boost::locale;
  14. int main(int argc,char **argv)
  15. {
  16. if(argc!=2) {
  17. std::cerr << "Usage backend locale" << std::endl;
  18. return 1;
  19. }
  20. boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
  21. mgr.select(argv[1]);
  22. generator gen(mgr);
  23. std::locale::global(gen(argv[2]));
  24. /// Set global locale to requested
  25. /// Create a set that includes all strings sorted according to ABC order
  26. /// std::locale can be used as object for comparison
  27. std::vector<std::string> all;
  28. typedef std::set<std::string,std::locale> set_type;
  29. set_type all_strings;
  30. /// Read all strings into the set
  31. while(!cin.eof()) {
  32. std::string tmp;
  33. getline(cin,tmp);
  34. all.push_back(tmp);
  35. }
  36. for(int i=0;i<10000;i++) {
  37. std::vector<std::string> tmp = all;
  38. std::sort(tmp.begin(),tmp.end(),std::locale());
  39. if(i==0) {
  40. for(unsigned j=0;j<tmp.size();j++)
  41. std::cout << tmp[j] << std::endl;
  42. }
  43. }
  44. }
  45. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4