string_view.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <cxxomfort/base.hpp>
  2. #include <cxxomfort/cstdio.hpp>
  3. #include <cxxomfort/string_view.hpp>
  4. #include <cxxomfort/ostream.hpp>
  5. #include <cxxomfort/library/type_name.hpp>
  6. #include <cstdio>
  7. #include <iostream>
  8. int main () {
  9. using namespace std;
  10. cxxomfort::output_info();
  11. cout<< endl;
  12. string_view fi = __DATE__;
  13. cout<< "std: User-defined literals:\n";
  14. #if (defined(__cpp_user_defined_literals) && defined(__cpp_lib_string_udls))
  15. using namespace std::literals::string_literals;
  16. cout<< "string"s << "\n";
  17. cout<< "string_view"sv << "\n";
  18. #else
  19. cout<< "N/A \n";
  20. #endif
  21. cout<< "\n";
  22. cout<< "cxxo: String helpers:\n";
  23. using namespace cxxomfort::fix::string_helpers;
  24. //cout<< s("string")<< "\n";
  25. cout<< sv("string_view")<< "\n";
  26. cout<< "\n";
  27. cout<< "cxxo_ _sv string literal:\n";
  28. #if defined(__cpp_user_defined_literals)
  29. using namespace cxxomfort::fix::string_literals;
  30. cout<< cxxomfort::typeid_demangle(typeid("string_view"_sv))<< endl;
  31. #else
  32. cout<< "N/A \n";
  33. #endif
  34. cout<< "\n";
  35. cout<< "string_view from a macro: ";
  36. cout<< "["<< fi<< "]"<< endl;
  37. string_view msg1 = "wololoooooo";
  38. string_view::iterator it1 = begin(msg1);
  39. (void)it1;
  40. string_view::const_iterator it2 = end(msg1);
  41. (void)it2;
  42. cout<< msg1<< endl;
  43. #if 0
  44. // this should fail:
  45. //msg1[1]= 'a';
  46. #endif
  47. }