view cclib.cc @ 2:ed80bcd28852

cclib
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 06 Mar 2023 10:13:49 +0100
parents
children 86e76ae3ac8a
line wrap: on
line source

#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;
}