update to c++20

v1
Brett 2023-07-24 13:00:35 -04:00
parent c3aab51030
commit 1998ddbafe
5 changed files with 34 additions and 30 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(BLT VERSION 0.6.1)
project(BLT VERSION 0.7.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
option(BUILD_STD "Build the BLT standard utilities." ON)
option(BUILD_PROFILING "Build the BLT profiler extension" ON)

View File

@ -1,5 +1,5 @@
# **BLT v0.6.1a**
A common utilities library I find useful
A C++20 common utilities library to make thing easy!
![Icon](icon_large.png)

View File

@ -33,28 +33,8 @@ namespace blt::nbt {
LONG_ARRAY = 12
};
class tag {
public:
virtual void writePayload(std::fstream& out) = 0;
virtual void readPayload(std::fstream& in) = 0;
};
class named_tag : public tag {
private:
std::string name;
public:
explicit named_tag(std::string name): name(std::move(name)) {}
named_tag() = default;
void writeName(std::fstream& out);
void readName(std::fstream& in);
};
class tag_end : public tag {
public:
void writePayload(std::fstream& out) final;
// nothing to read
void readPayload(std::fstream& in) final {}
};
void writeName(std::fstream& out, const std::string& name);
std::string readName(std::fstream& in);
class NBTDecoder {
private:

View File

@ -28,15 +28,15 @@ namespace blt::nbt {
return strOut;
}
void named_tag::writeName(std::fstream& out) {
void writeName(std::fstream& out, const std::string& name) {
writeUTF8String(out, name);
}
void named_tag::readName(std::fstream& in) {
name = readUTF8String(in);
std::string readName(std::fstream& in) {
return readUTF8String(in);
}
void tag_end::writePayload(std::fstream& out) {
void writePayload(std::fstream& out) {
out.put('\0');
}
}

View File

@ -46,6 +46,16 @@ class class_func : public super_func {
}
};
int (*func_func)(int) = [](int i) -> int {
int acc = 1;
for (int j = 0; j < i; j++){
acc += j * i;
}
return acc;
};
int (*func_func_in)(int) = &test_as_func;
int main(int argc, char** argv) {
if (argc > 1 && std::string(argv[1]) == "--no_color") {
@ -55,7 +65,7 @@ int main(int argc, char** argv) {
blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n");
}
class_func* funy = new class_func;
auto* funy = new class_func;
super_func* virtual_funy = new class_func;
int num_of_tests = 100000;
@ -88,6 +98,20 @@ int main(int argc, char** argv) {
}
BLT_END_INTERVAL("Functions Test", "virtual class");
BLT_START_INTERVAL("Functions Test", "funcptr lambda");
acc = 1;
for (int i = 0; i < num_of_tests; i++){
acc = func_func(acc);
}
BLT_END_INTERVAL("Functions Test", "funcptr lambda");
BLT_START_INTERVAL("Functions Test", "c function ptr");
acc = 1;
for (int i = 0; i < num_of_tests; i++){
acc = func_func_in(acc);
}
BLT_END_INTERVAL("Functions Test", "c function ptr");
BLT_PRINT_PROFILE("Functions Test");
delete virtual_funy;