changeset 2:ed80bcd28852

cclib
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 06 Mar 2023 10:13:49 +0100
parents ec6009463e1c
children 86e76ae3ac8a
files CMakeLists.txt cclib.cc
diffstat 2 files changed, 68 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Sun Mar 05 10:01:51 2023 +0100
+++ b/CMakeLists.txt	Mon Mar 06 10:13:49 2023 +0100
@@ -3,9 +3,14 @@
 
 ADD_SUBDIRECTORY(lib)
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -Wall -O")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -Wall")
+
 ADD_EXECUTABLE(time time.cc)
 TARGET_LINK_LIBRARIES(time exec)
 
 ADD_EXECUTABLE(arrays arrays.cc)
 TARGET_LINK_LIBRARIES(arrays exec)
+
+ADD_EXECUTABLE(cclib cclib.cc)
+TARGET_LINK_LIBRARIES(cclib exec)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cclib.cc	Mon Mar 06 10:13:49 2023 +0100
@@ -0,0 +1,62 @@
+#include <any>
+#include <array>
+#include <iostream>
+#include <regex>
+#include <string>
+#include <variant>
+#include <vector>
+#include <span>
+
+using namespace std;
+
+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();
+
+    return 0;
+}