From 1998ddbafef36ddaa303b6909c588e2d2b6d0497 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Jul 2023 13:00:35 -0400 Subject: [PATCH] update to c++20 --- CMakeLists.txt | 4 ++-- README.md | 2 +- include/blt/nbt/nbt.h | 24 ++---------------------- src/blt/nbt/nbt.cpp | 8 ++++---- src/tests/main.cpp | 26 +++++++++++++++++++++++++- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fcf8fb..a927605 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index dc17ad6..874ab2a 100755 --- a/README.md +++ b/README.md @@ -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) diff --git a/include/blt/nbt/nbt.h b/include/blt/nbt/nbt.h index f68f319..e41a4cd 100755 --- a/include/blt/nbt/nbt.h +++ b/include/blt/nbt/nbt.h @@ -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: diff --git a/src/blt/nbt/nbt.cpp b/src/blt/nbt/nbt.cpp index 9653f1b..0a38e03 100755 --- a/src/blt/nbt/nbt.cpp +++ b/src/blt/nbt/nbt.cpp @@ -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'); } } \ No newline at end of file diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 0c9d892..bd90c77 100755 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -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;