refactor: comnbine all in to one single header

This commit is contained in:
DL
2024-02-28 09:35:14 +01:00
parent 1664f86179
commit 8a96704909
6 changed files with 209 additions and 240 deletions

View File

@ -1,15 +1,15 @@
#include <string>
#include "../src/nerr.h"
#include "../src/ro.h"
#include <functional>
#include <iostream>
using namespace std;
using namespace nerr;
using namespace ro;
#define assert(v,fmt,...) if(!(v)) { \
throw Error(nerr::sfmt("ASSERT ERROR %s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)); \
throw Error(ro::sfmt("ASSERT ERROR %s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)); \
}
@ -20,18 +20,13 @@ void test(const char* desc, const std::function<void()>& lambda)
lambda();
std::cout << "OK" << std::endl;
}
catch(nerr::Error e)
catch(ro::Error e)
{
std::cout << "FAILED" << std::endl;
std::cout << e.what() << std::endl;
}
}
Result<string, Error> test_return()
{
return string("Error");
}
int main(int argc, char const *argv[])
{
test("Test Option", [](){
@ -123,7 +118,6 @@ int main(int argc, char const *argv[])
test("Result map", [](){
auto err = ERR("Error");
auto fn = [](string data){
cout << data << endl;
return 1;
};
Result<string, Error> ret = err;
@ -140,7 +134,6 @@ int main(int argc, char const *argv[])
test("Result map err", [](){
auto fn = [](int x){
cout << "Error code is " << x << endl;
return "Hello";
};
Result<bool, int> ret = true;
@ -165,4 +158,5 @@ int main(int argc, char const *argv[])
v = ret.map_or<int>(0, fn);
assert(v == 3, "Value mismatch %d",v);
});
}