Mercurial > lbo > hg > ccplay
view cclib.cc @ 24:b89680a8af68 default tip
graph: detect negative cycles
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 09 Apr 2023 17:27:20 +0200 |
parents | 86e76ae3ac8a |
children |
line wrap: on
line source
#include <algorithm> #include <any> #include <array> #include <iostream> #include <regex> #include <string> #include <variant> #include <vector> #include <span> using namespace std; constexpr vector<int> get_default_vector(void) { vector<int> v{1,15,25,35,45,65}; auto mid = find(v.begin(), v.end(), 35); vector<int> v2(v.begin(), mid+1); copy(v2.begin(), v2.end(), back_inserter(v)); return v; } template<typename It> void print_container(It begin, const It& end) { do { cout << *begin++ << " "; } while (begin != end); cout << endl; } void test_constexpr_functions(void) { auto v = get_default_vector(); cout << v.size() << endl; print_container(v.begin(), v.end()); } void test_any_copy(void) { int i = 10; any a1(i); any a2(a1); cout << any_cast<int>(a1) << endl; } void test_variant(void) { vector<variant<int,double,char>> v{1, 4.5, 'c'}; for (const auto& e : v) visit([](const int& ee) { cout << typeid(ee).name() << endl; }, e); } void test_span(void) { int arr[] = {1,2,3,4,5,6}; array<int, 6> a{to_array(arr)}; span<int> s(a); cout << *s.begin() << " " << *(s.end()-1) << endl; } void test_regex(void) { regex r("c(d|e)", regex_constants::extended); match_results<const char*> mr; regex_search("It is a pretty face", mr, r); static_assert(is_same<decltype(mr)::string_type, string>::value); cout << mr.begin()->str() << endl; } int main(int argc, char** argv) { if (argc < 2) { cerr << "need task supplied on command line!\n"; return 1; } string task(argv[1]); if (task == "test_any_copy") test_any_copy(); else if (task == "test_variant") test_variant(); else if (task == "test_span") test_span(); else if (task == "test_regex") test_regex(); else if (task == "test_constexpr_functions") test_constexpr_functions(); return 0; }