bogolyubskiyalexey

hse seminar: common editor

Sep 15th, 2020
1,065
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <vector>
  2.  
  3. printf("Hello, world!\n");
  4. pentagon.hack();
  5. t
  6. std::vector<T> get_even_numbers(std::vector<int>::iterator begin, It end) {
  7.  
  8.  
  9. template<class T, class It>
  10. It get_even_numbers(It begin, It end, It dest) {
  11.     return copy_if(begin, end, dest, [](T x) {return x % 2 == 0; });
  12. }
  13.  
  14.  
  15.  
  16. get_even_values<uint64_t>(values.begin(), values.end())
  17.  
  18.  
  19.     std::set<uint64_t> values = { 1,2,3,4 };
  20.     std::vector<uint64_t> result = get_even_values(
  21.         values.cbegin(),
  22.         values.cend()
  23.     );
  24.  
  25.  
  26.  
  27.  
  28. auto it = get_even_values2(
  29.         values.cbegin(),
  30.         values.cend(),
  31.         std::back_inserter(result)
  32.     );
  33.  
  34.  
  35. template<class It, class outputIt>
  36. It get_even_values2(It begin, It end, outputIt dest) {
  37.     for (; begin != end; begin++) {
  38.         if ((*begin) % 2 == 0) {
  39.             (*dest) = (*begin);
  40.             dest++;
  41.         }
  42.     }
  43.     return dest;
  44. }
  45.  
  46.  
  47.     auto result = sum(1, 5);
  48.     auto result2 = sum(1.0, 6.0);
  49.  
  50. template <typename T>
  51. T sum(const T& x, const T& y) {
  52.     return x + y;t
  53. }
  54.  
  55. template <>
  56. MyNumber sum(const MyNumber& x, const MyNumber& y) {
  57.     MyNumber result;
  58.     result.value = x.value + y.value;
  59.     return result;
  60. }
  61.  
  62.  
  63. struct MyNumber {
  64.     int value;
  65. };
  66.  
  67. MyNumber a, b;
  68. MyNumber c = sum(a, b)
  69.  
  70.  
  71.  
  72.  
  73.  
  74. create_set<std::set<int>>(100);
  75.  
  76.  
  77. template <typename T, class Z = typename T::value_type>
  78. T create_set(Z upTo) {
  79.     T t;
  80.     for (Z i = 1; i <= upTo; i++) {
  81.         t.insert(i);
  82.     }
  83.     return t;
  84. }
  85.  
  86. #include <chrono>
  87. using namespace std::chrono;
  88.  
  89. template<typename T>
  90. void timedFunc(typename T::value_type count) {
  91.     auto startTime = steady_clock::now();
  92.     create_set(count);
  93.     auto endTime = steady_clock::now();
  94.     auto elapsed_ms = duration_cast<milliseconds>(endTime - startTime);
  95.     std::cout << "The time: " << elapsed_ms.count() << " ms\n";
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
RAW Paste Data