soi-header/example.cpp

88 lines
2.4 KiB
C++
Raw Permalink Normal View History

// -*- compile-command: "g++ -Iinclude -D_GLIBCXX_DEBUG -fsanitize=address,undefined -g3 -ggdb3 -std=c++17 example.cpp -o example && SOI_COLOR=1 SOI_EOFCHECK=1 ./example <<< '4 5 blub 3 1 4'" -*-
2019-10-06 16:45:29 +02:00
#include <soi>
2019-10-07 14:29:45 +02:00
inline std::string methodName(const std::string& prettyFunction) {
size_t colons = prettyFunction.find("::");
size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
size_t end = prettyFunction.rfind("(") - begin;
return prettyFunction.substr(begin,end) + "()";
}
struct A{
void operator()() const {
2019-10-07 14:29:45 +02:00
dbg(methodName(__PRETTY_FUNCTION__));
dbg("here");
}
2019-10-07 14:29:45 +02:00
void bar(int a, int b, string c) const {
dbg("imbar");
}
void foo(int a=3, int b=5, string c="hi") const {
dbg("bar");
}
2019-10-07 14:29:45 +02:00
};
2019-10-06 18:37:37 +02:00
signed main() {
2019-10-07 14:29:45 +02:00
A a;
a();
a.foo();
a.bar(3,4,"hi");
print("this should not be in the output file");
redirect_output("example.out");
2019-10-10 14:28:35 +02:00
auto [i, j] = read<int, int>();
print(i, j);
print("read string",read<string>());
print('h','e','l','l','o');
print("false",'=',false);
print("true",'=',true);
print(read_vector<int>(3));
2019-10-07 14:29:45 +02:00
int l=3, r=5;
dbg(tuple{l, r});
2019-10-06 21:55:47 +02:00
dbg();
2019-10-06 16:45:29 +02:00
dbg("hi");
string s="world";
dbg(s);
2019-10-06 21:17:37 +02:00
dbg();
2019-10-06 16:45:29 +02:00
dbg(false);
dbg(true);
dbg('c');
vector<int> pi{3,1,4,1,5,9,2,6};
dbg(pi);
dbg(vector<int>{3,1,4,1,5,9,2,6});
2019-10-06 18:37:37 +02:00
dbg(vector<pair<int, int>>{{3,1},{4,1}});
dbg(vector<pair<int, vector<string>>>{{3,{"hi"}},{4,{"hello", "world"}}});
dbg(set<int>{3,1,4});
dbg(map<int, string>{{3,"three"},{1,"one"}});
2019-10-07 14:29:45 +02:00
dbg(tuple{unordered_map<int, string>{{3,"three"},{1,"one"}}});
dbg(unordered_set<int>{3,1,4});
print("v-- empty line");
print();
print("^-- empty line");
print("tuple",make_tuple(3, 1, 4, 1));
print(vector<int>{3,1,4,1,5,9,2,6});
print(vector<pair<int, int>>{{3,1},{4,1}});
print(vector<pair<int, vector<string>>>{{3,{"hi"}},{4,{"hello", "world"}}});
print(set<int>{3,1,4});
print(map<int, string>{{3,"three"},{1,"one"}});
print(tuple{unordered_map<int, string>{{3,"three"},{1,"one"}}});
print(unordered_set<int>{3,1,4});
print_no_space("Case #", 0, ": ");
print_no_space(42);
print_no_space();
print();
redirect_input("example.in");
print("reading from example.in:", read_string());
redirect_input("example.in");
print("reading from example.in:", read_string());
print("this is the last line on example.out");
reset_output();
print("this is stdout only");
2019-10-06 16:45:29 +02:00
}