Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <type_traits>
- #include <typeinfo>
- #include <regex>
- #include <algorithm>
- #include <vector>
- #include <thread>
- #include <chrono>
- #include <future>
- #include <mutex>
- using namespace std;
- template<class T>
- class A
- {
- T x;
- public:
- A() { }
- static void test()
- {
- cout << is_pointer<T>::value << endl;
- cout << is_same<T, int>::value << endl;
- if (typeid(T) == typeid(int*))
- cout << "Test" << endl;
- cout << typeid(T).name() << endl;
- //cout << type_info(T).name() << endl;
- }
- };
- class Term {
- char* key;
- char* value;
- public:
- Term(const char* k, const char* v) {
- key = new char[strlen(k) + 1];
- value = new char[strlen(v) + 1];
- strcpy_s(key, strlen(k) + 1, k);
- strcpy_s(value, strlen(v) + 1, v);
- }
- Term() :key(nullptr), value(nullptr) {}
- Term(const Term& t1) {
- if (t1.key != nullptr) {
- key = new char[strlen(t1.key) + 1];
- strcpy_s(key, strlen(t1.key) + 1, t1.key);
- }
- if (t1.value != nullptr) {
- value = new char[strlen(t1.value) + 1];
- strcpy_s(value, strlen(t1.value) + 1, t1.value);
- }
- }
- Term& operator=(const Term& t1) {
- if (this != &t1) {
- delete[] key;
- delete[] value;
- value = new char[strlen(t1.value) + 1];
- strcpy_s(value, strlen(t1.value) + 1, t1.value);
- key = new char[strlen(t1.key) + 1];
- strcpy_s(key, strlen(t1.key) + 1, t1.key);
- } return *this;
- }
- };
- template <class T>
- class C
- {
- private:
- T a; //int*
- public:
- C()
- {
- typedef remove_pointer<T>::type B; // B = int
- a = new B(25); // "new int"
- }
- ~C() { delete a; }
- void Print() { cout << a << " " << *a << endl; }
- };
- int SayHello(int x)
- {
- cout << "Hello World!" << x << endl;
- this_thread::sleep_for(chrono::seconds(x));
- return x;
- }
- void dummy(int& x)
- {
- this_thread::sleep_for(chrono::seconds(5));
- cout << "ĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆĆ";
- }
- string ln = "\n-------------------------------------\n";
- void PosaljiEmailPoruke() {
- cout << ln << "PosaljiEmailPoruke :: nit ID -> " << this_thread::get_id()
- << ln;
- }
- int value = 0;
- mutex my;
- void DoWork()
- {
- for (int i = 0; i < 1000; i++)
- {
- my.lock();
- cout << value << "\n";
- value++;
- my.unlock();
- }
- }
- int main()
- {
- /*string str = "Hello World!";
- string sstr = "rld";
- string t = "tes";
- if (str.find(t) > str.length())
- cout << "Not found" << endl;
- else
- cout << "Found" << endl;
- cout << str.substr(5) << endl;
- A<int*>::test();
- int x = 30;
- cout << "x = " << x << endl;
- Change(ref(x));
- cout << "x = " << x << endl;
- */
- /*string rules = "^[a-zA-Z]+[0-9]*";
- string pw = "Arman123";
- //string rules = "^[[:alpha]]{1,}.\\d{1,}*";
- //string pw = "Arman123";
- if (regex_search(pw, regex(rules)))
- cout << pw << endl;
- if (regex_match(pw, regex(rules)))
- cout << pw << endl;*/
- /*Term t1("harun", "konj");
- Term t2("harun", "horse");
- vector<Term>termini;
- termini.push_back(t1);
- termini.push_back(t2);
- vector<Term>::iterator it = termini.begin();
- termini.erase(it);*/
- C<int*> a;
- a.Print();
- //this_thread::sleep_for(chrono::seconds(2));
- /*thread t(&SayHello, 5);
- t.join();*/
- /*std::future<int> f = async(&SayHello, 2); //join
- int x = f.get();
- cout << x << endl;
- thread t(dummy, ref(x));
- t.detach();*/
- string indexrule("IB[0-9]{6}");
- string index = "IB160021";
- if (regex_match(index, regex(indexrule)))
- cout << "Index correct: " << index << endl;
- string daterule("[0-9]{2}.[0-9]{1,2}.[0-9]{4}");
- string date = "21.02.2018";
- if (regex_match(date, regex(daterule)))
- cout << "Date " << date << " is valid!" << endl;
- string days = date.substr(0, 2);
- string yearstring = date.substr(date.length() - 4);
- string month = date.substr(date.length() - 7, date.length() - 5);
- int day = atoi(days.c_str());
- int m = atoi(month.c_str());
- int year = atoi(yearstring.c_str());
- cout << day << " " << m << " " << year << endl;
- string emailrule("[a-zA-Z0-9][a-zA-Z0-9_.]+[a-zA-Z0-9]@[a-zA-Z0-9]+.[a-zA-Z0-9]+");
- string email = "nizama@test.com";
- if (regex_match(email, regex(emailrule)))
- cout << email << " is in correct format!" << endl;
- _getch();
- return 0; //Or you can go and fuck yourself
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement