#include <iostream>
#include <vector>
#include <tuple>
#include <bitset>
#include <regex>
#include <random>
using namespace std;
void TupleTest();
void BitsetTest();
void RegexTest();
void Randomtest();
void IOTest();
int main()
{
TupleTest();
BitsetTest();
RegexTest();
Randomtest();
IOTest();
cout << "enter key" << endl;
while (cin.get() != EOF)
{
}
return 0;
}
void TupleTest()
{
tuple<int, string> tuple1 = {1, "ab"};
get<0>(tuple1);
get<0>(tuple1) = 2;
int size = tuple_size<decltype(tuple1)>::value;
tuple_element<0, decltype(tuple1)>::type a;
}
void BitsetTest()
{
bitset<16> bit1(0xfffe);
bitset<8> bit2("11001111");
bit1.any();
bit1.all();
bit1.count();
bit1.test(8);
bit1.set(8, true);
bit1.reset(8);
bit1.to_string();
}
void RegexTest()
{
string testStr = "abcdefgh";
regex r("(a.*?c)d(ef)");
smatch sresult;
if (regex_search(testStr, sresult, r))
{
cout << sresult.str() << endl;
cout << sresult.str(1) << endl;
}
string replacefmt = "$1.$2";
cout << regex_replace(testStr, r, replacefmt) << endl;
}
void Randomtest()
{
static default_random_engine random1;
cout << random1() << endl;
static uniform_int_distribution<unsigned> u(0, 9);
cout << u(random1) << endl;
static uniform_real_distribution<double> ud(0, 1);
cout << ud(random1) << endl;
default_random_engine random2(8737);
normal_distribution<> n(4, 1.5);
cout << n(random1) << endl;
}
void IOTest()
{
cout << boolalpha << true << noboolalpha << endl;
char c;
cin >> noskipws;
while (cin >> c)
{
cout << c;
};
cin >> skipws;
cout << endl;
cout << cin.fail() << endl;
char c1;
cin.get(c1);
cout.put(c1);
c1 = cin.peek();
cin.unget();
cin.putback(c1);
auto ipos = cin.tellg();
cin.seekg(ipos);
auto opos = cout.tellp();
cout.seekp(opos);
}