diff --git a/build.zig b/build.zig index e82f95a..2defde7 100644 --- a/build.zig +++ b/build.zig @@ -38,6 +38,9 @@ const boost_libs = [_][]const u8{ "graph", "optional", "date_time", + "mysql", + "compute", + "safe_numerics", "smart_ptr", "math", "beast", @@ -49,6 +52,13 @@ const boost_libs = [_][]const u8{ "io", "json", "type_index", + "timer", + "stacktrace", + "sort", + "filesystem", + "context", + "signals2", + "interprocess", "container", "variant", "variant2", @@ -56,6 +66,28 @@ const boost_libs = [_][]const u8{ "chrono", "any", "url", + "wave", + "atomic", + "scope", + "process", + "fusion", + "function", + "spirit", + "cobalt", + "phoenix", + "nowide", + "locale", + "circular_buffer", + "uuid", + "leaf", + "redis", + "lockfree", + "parameter", + "tokenizer", + "geometry", + "crc", + "compat", + "bimap", }; pub fn build(b: *std.Build) !void { diff --git a/build.zig.zon b/build.zig.zon index c27096e..fb70814 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -222,6 +222,134 @@ .url = "git+https://github.com/boostorg/multi_array#boost-1.86.0", .hash = "1220871e233a05ee79c380dff922c83b20f4c738ab8e347c3c804d1c89430cb06ad6", }, + .safe_numerics = .{ + .url = "git+https://github.com/boostorg/safe_numerics#boost-1.86.0", + .hash = "12208727dd01a888969589858e991a10a7a354f6047edab0ee022c6681816e5cea16", + }, + .filesystem = .{ + .url = "git+https://github.com/boostorg/filesystem#boost-1.86.0", + .hash = "122047d93f21af11ef3aa0e6338d84b1d25b2efeb31a8672090a5eda55cccde5a584", + }, + .compute = .{ + .url = "git+https://github.com/boostorg/compute#boost-1.86.0", + .hash = "12202342c11fa186526bafdbfd1ec7be79dad7a12b06087e266173df352282a35b96", + }, + .mysql = .{ + .url = "git+https://github.com/boostorg/mysql#boost-1.86.0", + .hash = "1220e349c84f7f39edd46fce54994381c3bea74c4dda1cb66e4cbac101fe8f5b87e2", + }, + .sort = .{ + .url = "git+https://github.com/boostorg/sort#boost-1.86.0", + .hash = "12205660c462a1d601b45d8b47595a3ed18984e31b8d4a4c608cd0e492b63771145c", + }, + .stacktrace = .{ + .url = "git+https://github.com/boostorg/stacktrace#boost-1.86.0", + .hash = "12203bf4b6c54366939e09d184f3414b466a5fe24fbc662e01c77ff374040db36809", + }, + .signals2 = .{ + .url = "git+https://github.com/boostorg/signals2#boost-1.86.0", + .hash = "122016600e91bdbde5c63398f03c4ec6a82b3173963d4450950627b6ee75f4342776", + }, + .interprocess = .{ + .url = "git+https://github.com/boostorg/interprocess#boost-1.86.0", + .hash = "1220d156a4ff1a4d3a19091feff9b2ae4733d804634519e215d74845b76b65467b91", + }, + .context = .{ + .url = "git+https://github.com/boostorg/context#boost-1.86.0", + .hash = "122071a51657a3f9f4c838729c2a5e3233850ded03cdf762b82ff89d1e64d6088042", + }, + .timer = .{ + .url = "git+https://github.com/boostorg/timer#boost-1.86.0", + .hash = "1220c8394ce0da05ccc92515cf878195b843c62488a22d8444f6bece16f670e92b94", + }, + .wave = .{ + .url = "git+https://github.com/boostorg/wave#boost-1.86.0", + .hash = "12207080d64a699097c996ff10d842057946f7ddf8971b3a24fb4f651d21c773fff0", + }, + .atomic = .{ + .url = "git+https://github.com/boostorg/atomic#boost-1.86.0", + .hash = "122079d35f4a01c8f32e415cbb7e089f3dc115cf7c1278bd6162b9db9e78d956e4e1", + }, + .scope = .{ + .url = "git+https://github.com/boostorg/scope#boost-1.86.0", + .hash = "1220dc5b4ae5d138150ecc69b449a5a9d547dc83bbf8ccf664ee6f9fa04610936c64", + }, + .process = .{ + .url = "git+https://github.com/boostorg/process#boost-1.86.0", + .hash = "12204649be43017f4ac82d10fc3eb280bb839e0b46ae5433603f97a778fa7156cff6", + }, + .fusion = .{ + .url = "git+https://github.com/boostorg/fusion#boost-1.86.0", + .hash = "1220b8a44801c94a784e9849befb66e3be820fca3c04cd78abf4f819128183f58817", + }, + .spirit = .{ + .url = "git+https://github.com/boostorg/spirit#boost-1.86.0", + .hash = "1220c1d8de2af3095b2dd8370ee02c49187a17ab0e5906de6aba326f6c70a0f444df", + }, + .function = .{ + .url = "git+https://github.com/boostorg/function#boost-1.86.0", + .hash = "12202dcac10101564252c3b9194f125ca52e4aaa28958596d21367e0dd240fce351d", + }, + .cobalt = .{ + .url = "git+https://github.com/boostorg/cobalt#boost-1.86.0", + .hash = "12207b4f1ea91e5bd181a43935358a44ca0bf347418c8ea73a0f49cca777e48e81a0", + }, + .phoenix = .{ + .url = "git+https://github.com/boostorg/phoenix#boost-1.86.0", + .hash = "1220b0aeceeb3bf22f072cba2edf66ecef7e6d82cbe49c5b5b0e8cf5f842a1807681", + }, + .locale = .{ + .url = "git+https://github.com/boostorg/locale#boost-1.86.0", + .hash = "12202e697191394f3b14bec01fc0450af325c8765c1774bba99d5a7a2fe4838d17ac", + }, + .uuid = .{ + .url = "git+https://github.com/boostorg/uuid#boost-1.86.0", + .hash = "1220d17e61663fe1788bcc22d4d66eeb5fc3e1583b900ba5142effbe4ad615f11663", + }, + .nowide = .{ + .url = "git+https://github.com/boostorg/nowide#boost-1.86.0", + .hash = "1220ee5b39c957b4a51d0c0a01c75a7e4c8779df9715afed2ba0694d36d2b3c2a34f", + }, + .circular_buffer = .{ + .url = "git+https://github.com/boostorg/circular_buffer#boost-1.86.0", + .hash = "1220a83deb2b81535c851b38903fa778ceac6fd71369786788e3e8804581d5d1fe02", + }, + .leaf = .{ + .url = "git+https://github.com/boostorg/leaf#boost-1.86.0", + .hash = "1220658a802388aef324a0bb0c139148cb747d846f68d5a45229fce964ee3fa1f12b", + }, + .lockfree = .{ + .url = "git+https://github.com/boostorg/lockfree#boost-1.86.0", + .hash = "12204b17cda3a13cfd2dbee03f6ed0c25f1da46f8bd70bd4809436bc1f1e2ca8cb78", + }, + .redis = .{ + .url = "git+https://github.com/boostorg/redis#boost-1.86.0", + .hash = "1220daf32ca160644030a527b6690bbf67164d40dba61254eaa297195ee9fa05d5d8", + }, + .geometry = .{ + .url = "git+https://github.com/boostorg/geometry#boost-1.86.0", + .hash = "122045d4892ad25f43c1daf26687c0ce62445c331c16420b0dcb3eaf600433d9c0eb", + }, + .crc = .{ + .url = "git+https://github.com/boostorg/crc#boost-1.86.0", + .hash = "1220f67f5901d30e6c8ab4553630cfa31bdf8ceb0ba576cd6798011b1ab9ab47c846", + }, + .compat = .{ + .url = "git+https://github.com/boostorg/compat#boost-1.86.0", + .hash = "1220ec67159a5eaee64a4b09dc3adc5fd9b8a6dbf0e33e1bcb53670ca8c6d025a9c2", + }, + .bimap = .{ + .url = "git+https://github.com/boostorg/bimap#boost-1.86.0", + .hash = "12206800bb00551a163262f7fa128080060f529d67ec70e7c6ac5590b56ca6c25ee5", + }, + .tokenizer = .{ + .url = "git+https://github.com/boostorg/tokenizer#boost-1.86.0", + .hash = "12200550afc5cd910a174e605c929d0644f3ad0f2e3f6167334dbc236853cc76ac10", + }, + .parameter = .{ + .url = "git+https://github.com/boostorg/parameter#boost-1.86.0", + .hash = "122053c2d2c58149a0a1a84491b6a7dbb156d6cf3410d7e04a6683ca2671611bf578", + }, }, .paths = .{""}, } diff --git a/tests/build.zig b/tests/build.zig index 2f39990..3b9b6fc 100644 --- a/tests/build.zig +++ b/tests/build.zig @@ -43,6 +43,7 @@ fn buildTests(b: *std.Build, options: struct { for (options.files) |file| { exe.addCSourceFile(.{ .file = b.path(file), + .flags = &.{"-std=c++20"}, }); } if (exe.rootModuleTarget().abi != .msvc) { @@ -56,4 +57,7 @@ fn buildTests(b: *std.Build, options: struct { exe.linkSystemLibrary("ws2_32"); b.installArtifact(exe); + const run_cmd = b.addRunArtifact(exe); + const run_step = b.step("run", b.fmt("Run the {s}", .{exe.name})); + run_step.dependOn(&run_cmd.step); } diff --git a/tests/include_all.cc b/tests/include_all.cc index 8152aee..658413d 100644 --- a/tests/include_all.cc +++ b/tests/include_all.cc @@ -4,11 +4,17 @@ #include #include #include +#include #include +#include +#include #include #include #include +#include +#include #include +#include #include #include #include @@ -18,6 +24,13 @@ using namespace boost; +void testVariants(); +void testCRC(); +void testSafeIntegers(); +void testHana(); +void testMultiArray(); +void testSignals2(); + int main() { std::cout << "Boost version " << BOOST_VERSION / 100000 << "." << BOOST_VERSION / 100 % 1000 << "." << BOOST_VERSION % 100 @@ -25,7 +38,93 @@ int main() { asio::io_context io_service; - // Example using boost::variant + testCRC(); + testSafeIntegers(); + testVariants(); + testHana(); + testMultiArray(); + testSignals2(); + + return 0; +} + +void testSafeIntegers() { + + safe_numerics::safe x(10); + safe_numerics::safe y(20); + + // addition + auto sum = x + y; + std::cout << "Safe addition: " << sum << std::endl; + + // subtraction + auto difference = y - x; + std::cout << "Safe subtraction: " << difference << std::endl; + + // multiplication + auto product = x * y; + std::cout << "Safe multiplication: " << product << std::endl; + + // division + auto quotient = y / x; + std::cout << "Safe division: " << quotient << std::endl; + + // Overflow detection + try { + safe_numerics::safe small_int = 100; + small_int *= 2; + } catch (const std::exception &e) { + std::cout << "Overflow detected: " << e.what() << std::endl; + } + + // Underflow detection + try { + safe_numerics::safe unsigned_int = 0; + unsigned_int--; + } catch (const std::exception &e) { + std::cout << "Underflow detected: " << e.what() << std::endl; + } +} + +void testCRC() { + // Sample data + const char *data = "Hello, Boost CRC!"; + std::size_t len = std::strlen(data); + + // Create a CRC-32 object + boost::crc_32_type crc; + + // Process the data + crc.process_bytes(data, len); + + // Get the CRC checksum + uint32_t checksum = crc.checksum(); + + std::cout << "CRC-32 checksum: 0x" << std::hex << std::uppercase << checksum + << std::endl; + + // Reset the CRC object for reuse + crc.reset(); + + // Process data in chunks + crc.process_bytes(data, 5); + crc.process_bytes(data + 5, len - 5); + + // Get the new checksum + uint32_t new_checksum = crc.checksum(); + + std::cout << "CRC-32 checksum (chunked): 0x" << std::hex << std::uppercase + << new_checksum << std::endl; + + // Verify that both methods produce the same result + if (checksum == new_checksum) { + std::cout << "Checksums match!" << std::endl; + } else { + std::cout << "Checksums do not match!" << std::endl; + } +} + +void testVariants() { variant v; v = 42; @@ -58,6 +157,115 @@ int main() { v = 2.718; apply_visitor(visitor(), v); +} - return 0; +void testMultiArray() { + // Define a 3D array with dimensions 3x4x2 + typedef multi_array array_type; + array_type A(extents[3][4][2]); + + // Fill the array with some values + int value = 0; + for (int i = 0; i < 3; ++i) + for (int j = 0; j < 4; ++j) + for (int k = 0; k < 2; ++k) + A[i][j][k] = value++; + + // Print the array + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 4; ++j) { + for (int k = 0; k < 2; ++k) { + std::cout << A[i][j][k] << " "; + } + std::cout << std::endl; + } + std::cout << std::endl; + } + + // Demonstrate slicing + typedef array_type::index_range range; + array_type::array_view<2>::type myview = + A[boost::indices[1][range()][range()]]; + + std::cout << "View of the second 'layer' of the 3D array:" << std::endl; + for (int j = 0; j < 4; ++j) { + for (int k = 0; k < 2; ++k) { + std::cout << myview[j][k] << " "; + } + std::cout << std::endl; + } +} + +void testHana() { + struct Person { + BOOST_HANA_DEFINE_STRUCT(Person, (std::string, name), (int, age)); + }; + + // Create an instance of Person + auto person = Person{"Alice", 30}; + + // Use Hana to iterate over the struct members + hana::for_each(hana::members(person), [](auto member) { + std::cout << "Member value: " << member << std::endl; + }); + + // Use Hana's type-level computations + auto types = hana::tuple_t; + + std::cout << "Number of types: " << hana::length(types) << std::endl; + + // Check if int is among the types + constexpr auto has_int = hana::contains(types, hana::type_c); + std::cout << "Contains int: " << has_int << std::endl; + + // Transform the tuple of types + auto sizes = hana::transform(types, [](auto t) { return hana::sizeof_(t); }); + + std::cout << "Sizes of types: "; + hana::for_each(sizes, [](auto size) { std::cout << size << " "; }); + std::cout << std::endl; +} + +void testSignals2() { + // Define a signal with two parameters + signals2::signal sig; + + // Define some slot functions + auto slot1 = [](int n, const std::string &str) { + std::cout << "Slot 1: " << n << ", " << str << std::endl; + }; + + auto slot2 = [](int n, const std::string &str) { + std::cout << "Slot 2: " << n << ", " << str << std::endl; + }; + + // Connect the slots to the signal + sig.connect(slot1); + sig.connect(slot2); + + // Emit the signal + std::cout << "Emitting signal:" << std::endl; + sig(42, "Hello, Boost.Signals2!"); + + // Disconnect slot1 + sig.disconnect(slot1); + + // Emit the signal again + std::cout << "Emitting signal after disconnecting slot1:" << std::endl; + sig(100, "Signal emitted again"); + + // Use scoped_connection for automatic disconnection + { + signals2::scoped_connection conn = + sig.connect([](int n, const std::string &str) { + std::cout << "Temporary slot: " << n << ", " << str << std::endl; + }); + + std::cout << "Emitting signal with temporary slot:" << std::endl; + sig(200, "Temporary connection"); + } // conn goes out of scope here and disconnects + + // Emit signal one last time + std::cout << "Final signal emission:" << std::endl; + sig(300, "Final emission"); } \ No newline at end of file diff --git a/update_zon.sh b/update_zon.sh index 0224666..d09412b 100755 --- a/update_zon.sh +++ b/update_zon.sh @@ -56,6 +56,41 @@ GIT_URLS=( "git+https://github.com/boostorg/unordered#$BOOST_VERSION" "git+https://github.com/boostorg/any#$BOOST_VERSION" "git+https://github.com/boostorg/url#$BOOST_VERSION" + "git+https://github.com/boostorg/multi_array#$BOOST_VERSION" + "git+https://github.com/boostorg/integer#$BOOST_VERSION" + "git+https://github.com/boostorg/array#$BOOST_VERSION" + "git+https://github.com/boostorg/safe_numerics#$BOOST_VERSION" + "git+https://github.com/boostorg/filesystem#$BOOST_VERSION" + "git+https://github.com/boostorg/compute#$BOOST_VERSION" + "git+https://github.com/boostorg/mysql#$BOOST_VERSION" + "git+https://github.com/boostorg/sort#$BOOST_VERSION" + "git+https://github.com/boostorg/stacktrace#$BOOST_VERSION" + "git+https://github.com/boostorg/signals2#$BOOST_VERSION" + "git+https://github.com/boostorg/interprocess#$BOOST_VERSION" + "git+https://github.com/boostorg/context#$BOOST_VERSION" + "git+https://github.com/boostorg/timer#$BOOST_VERSION" + "git+https://github.com/boostorg/wave#$BOOST_VERSION" + "git+https://github.com/boostorg/atomic#$BOOST_VERSION" + "git+https://github.com/boostorg/scope#$BOOST_VERSION" + "git+https://github.com/boostorg/process#$BOOST_VERSION" + "git+https://github.com/boostorg/fusion#$BOOST_VERSION" + "git+https://github.com/boostorg/function#$BOOST_VERSION" + "git+https://github.com/boostorg/spirit#$BOOST_VERSION" + "git+https://github.com/boostorg/cobalt#$BOOST_VERSION" + "git+https://github.com/boostorg/phoenix#$BOOST_VERSION" + "git+https://github.com/boostorg/locale#$BOOST_VERSION" + "git+https://github.com/boostorg/uuid#$BOOST_VERSION" + "git+https://github.com/boostorg/nowide#$BOOST_VERSION" + "git+https://github.com/boostorg/circular_buffer#$BOOST_VERSION" + "git+https://github.com/boostorg/leaf#$BOOST_VERSION" + "git+https://github.com/boostorg/lockfree#$BOOST_VERSION" + "git+https://github.com/boostorg/redis#$BOOST_VERSION" + "git+https://github.com/boostorg/geometry#$BOOST_VERSION" + "git+https://github.com/boostorg/crc#$BOOST_VERSION" + "git+https://github.com/boostorg/compat#$BOOST_VERSION" + "git+https://github.com/boostorg/bimap#$BOOST_VERSION" + "git+https://github.com/boostorg/tokenizer#$BOOST_VERSION" + "git+https://github.com/boostorg/parameter#$BOOST_VERSION" ## Add more URLs here )