iterator_accesors.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Test the global iterators accessors:
  3. * * C++11 begin, end
  4. * * C++14 rbegin, rend
  5. * * C++17 size, empty, data
  6. *
  7. * */
  8. #include <cxxomfort/base.hpp>
  9. #include <cxxomfort/array.hpp>
  10. #include <cxxomfort/iterator.hpp>
  11. //#include <cxxomfort/library/fixed_vector.hpp>
  12. #include <cxxomfort/library/type_name.hpp>
  13. #include <iostream>
  14. #include <list>
  15. #include <vector>
  16. #include <ctime>
  17. #include <cstdlib>
  18. typedef unsigned Type;
  19. int main () {
  20. using namespace std;
  21. using cxxomfort::library::typeid_demangle;
  22. cxxomfort::output_info(stdout); cout<< endl;
  23. srand(time(0));
  24. cout<< "C++11 accessors: "<< CXXO_COMPILER_SUPPORT_iterator_accessors_11<< " "<< CXXOMFORT_IMPLEMENTS_iterator_accessors_11<< endl;
  25. cout<< "C++14 accessors: "<< CXXO_COMPILER_SUPPORT_iterator_accessors_14<< " "<< CXXOMFORT_IMPLEMENTS_iterator_accessors_14<< endl;
  26. cout<< "C++17 accessors: "<< CXXO_COMPILER_SUPPORT_iterator_accessors_17<< " "<< CXXOMFORT_IMPLEMENTS_iterator_accessors_17<< endl;
  27. //cout<< "p1227 accessors: "<< CXXOMFORT_IMPLEMENTS_p1227r0<< endl;
  28. cout<< "ssize: "<< CXXOMFORT_IMPLEMENTS_ssize<< endl;
  29. list<Type> V(20);
  30. // check the C++11 global accessors
  31. generate (begin(V), end(V), rand);
  32. cout<< endl;
  33. // check the C++14 global accessors
  34. vector<Type> W(V.size());
  35. copy (cbegin(V), cend(V), rbegin(W));
  36. cout<< "V:\t";
  37. CXXO_FOREACH(Type x, V) {
  38. cout<< x<< " ";
  39. } cout<< endl;
  40. cout<< "W:\t";
  41. CXXO_FOREACH(Type x, W) {
  42. cout<< x<< " ";
  43. } cout<< endl;
  44. #if 0
  45. // check the C++17 accessors
  46. cout<< "type of container: "<< typeid_demangle(typeid(V))<< endl;
  47. cout<< "size() : "<< V.size()<< endl;
  48. cout<< "type of size(): "<< typeid_demangle( typeid(V.size()) )<< endl;
  49. cout<< "std::size(V) : "<< size(V)<< endl;
  50. cout<< "type of std::size: "<< typeid_demangle( typeid(size(V)) )<< endl;
  51. cout<< "std::ssize(V) : "<< ssize(V)<< endl;
  52. cout<< "type of std::ssize: "<< typeid_demangle( typeid(ssize(V)) )<< endl;
  53. cout<< "std::empty(V) : "<< empty(V)<< endl;
  54. cout<< "type of std::empty: "<< typeid_demangle( typeid(empty(V)) )<< endl;
  55. //cout<< "std::data(V) : "<< (void*)data(V)<< endl;
  56. //cout<< "type of std::data: "<< typeid_demangle( typeid(data(V)) )<< endl;
  57. #endif
  58. }