Advertisement
Guest User

Arman

a guest
Jul 19th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <type_traits>
  5. #include <typeinfo>
  6. #include <regex>
  7. #include <algorithm>
  8. #include <vector>
  9. #include <thread>
  10. #include <chrono>
  11. #include <future>
  12. #include <mutex>
  13.  
  14. using namespace std;
  15.  
  16. template<class T>
  17. class A
  18. {
  19.     T x;
  20. public:
  21.     A() { }
  22.     static void test()
  23.     {
  24.         cout << is_pointer<T>::value << endl;
  25.         cout << is_same<T, int>::value << endl;
  26.         if (typeid(T) == typeid(int*))
  27.             cout << "Test" << endl;
  28.         cout << typeid(T).name() << endl;
  29.         //cout << type_info(T).name() << endl;
  30.     }
  31. };
  32.  
  33. class Term {
  34.     char* key;
  35.     char* value;
  36. public:
  37.     Term(const char* k, const char* v) {
  38.         key = new char[strlen(k) + 1];
  39.         value = new char[strlen(v) + 1];
  40.         strcpy_s(key, strlen(k) + 1, k);
  41.         strcpy_s(value, strlen(v) + 1, v);
  42.     }
  43.     Term() :key(nullptr), value(nullptr) {}
  44.     Term(const Term& t1) {
  45.         if (t1.key != nullptr) {
  46.             key = new char[strlen(t1.key) + 1];
  47.             strcpy_s(key, strlen(t1.key) + 1, t1.key);
  48.         }
  49.         if (t1.value != nullptr) {
  50.             value = new char[strlen(t1.value) + 1];
  51.             strcpy_s(value, strlen(t1.value) + 1, t1.value);
  52.         }
  53.     }
  54.     Term& operator=(const Term& t1) {
  55.         if (this != &t1) {
  56.             delete[] key;
  57.             delete[] value;
  58.             value = new char[strlen(t1.value) + 1];
  59.             strcpy_s(value, strlen(t1.value) + 1, t1.value);
  60.             key = new char[strlen(t1.key) + 1];
  61.             strcpy_s(key, strlen(t1.key) + 1, t1.key);
  62.         } return *this;
  63.     }
  64. };
  65.  
  66. template <class T>
  67. class C
  68. {
  69. private:
  70.     T a; //int*
  71. public:
  72.     C()
  73.     {
  74.         typedef remove_pointer<T>::type B; // B = int
  75.         a = new B(25); // "new int"
  76.     }
  77.     ~C() { delete a; }
  78.     void Print() { cout << a << " " << *a << endl; }
  79. };
  80.  
  81. int SayHello(int x)
  82. {
  83.     cout << "Hello World!" << x << endl;
  84.     this_thread::sleep_for(chrono::seconds(x));
  85.     return x;
  86. }
  87.  
  88. void dummy(int& x)
  89. {
  90.     this_thread::sleep_for(chrono::seconds(5));
  91.     cout << "ĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆ";
  92. }
  93. string ln = "\n-------------------------------------\n";
  94. void PosaljiEmailPoruke() {
  95.     cout << ln << "PosaljiEmailPoruke :: nit ID -> " << this_thread::get_id()
  96.         << ln;
  97. }
  98.  
  99. int value = 0;
  100. mutex my;
  101. void DoWork()
  102. {
  103.     for (int i = 0; i < 1000; i++)
  104.     {
  105.         my.lock();
  106.         cout << value << "\n";
  107.         value++;
  108.         my.unlock();
  109.     }
  110. }
  111.  
  112. int main()
  113. {
  114.     /*string str = "Hello World!";
  115.     string sstr = "rld";
  116.     string t = "tes";
  117.     if (str.find(t) > str.length())
  118.     cout << "Not found" << endl;
  119.     else
  120.     cout << "Found" << endl;
  121.     cout << str.substr(5) << endl;
  122.  
  123.     A<int*>::test();
  124.  
  125.     int x = 30;
  126.     cout << "x = " << x << endl;
  127.     Change(ref(x));
  128.     cout << "x = " << x << endl;
  129.     */
  130.  
  131.     /*string rules = "^[a-zA-Z]+[0-9]*";
  132.     string pw = "Arman123";
  133.     //string rules = "^[[:alpha]]{1,}.\\d{1,}*";
  134.     //string pw = "Arman123";
  135.  
  136.     if (regex_search(pw, regex(rules)))
  137.     cout << pw << endl;
  138.     if (regex_match(pw, regex(rules)))
  139.     cout << pw << endl;*/
  140.  
  141.     /*Term t1("harun", "konj");
  142.     Term t2("harun", "horse");
  143.  
  144.     vector<Term>termini;
  145.     termini.push_back(t1);
  146.     termini.push_back(t2);
  147.     vector<Term>::iterator it = termini.begin();
  148.     termini.erase(it);*/
  149.  
  150.     C<int*> a;
  151.     a.Print();
  152.  
  153.     //this_thread::sleep_for(chrono::seconds(2));
  154.  
  155.     /*thread t(&SayHello, 5);
  156.     t.join();*/
  157.  
  158.     /*std::future<int> f = async(&SayHello, 2); //join
  159.     int x = f.get();
  160.     cout << x << endl;
  161.  
  162.     thread t(dummy, ref(x));
  163.     t.detach();*/
  164.  
  165.     string indexrule("IB[0-9]{6}");
  166.     string index = "IB160021";
  167.     if (regex_match(index, regex(indexrule)))
  168.         cout << "Index correct: " << index << endl;
  169.  
  170.     string daterule("[0-9]{2}.[0-9]{1,2}.[0-9]{4}");
  171.     string date = "21.02.2018";
  172.     if (regex_match(date, regex(daterule)))
  173.         cout << "Date " << date << " is valid!" << endl;
  174.     string days = date.substr(0, 2);
  175.     string yearstring = date.substr(date.length() - 4);
  176.     string month = date.substr(date.length() - 7, date.length() - 5);
  177.     int day = atoi(days.c_str());
  178.     int m = atoi(month.c_str());
  179.     int year = atoi(yearstring.c_str());
  180.     cout << day << " " << m << " " << year << endl;
  181.    
  182.     string emailrule("[a-zA-Z0-9][a-zA-Z0-9_.]+[a-zA-Z0-9]@[a-zA-Z0-9]+.[a-zA-Z0-9]+");
  183.     string email = "nizama@test.com";
  184.     if (regex_match(email, regex(emailrule)))
  185.         cout << email << " is in correct format!" << endl;
  186.  
  187.     _getch();
  188.     return 0; //Or you can go and fuck yourself
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement