-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const boost_dep = b.dependency("boost", .{ | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
buildTests(b, .{ | ||
.target = target, | ||
.optimize = optimize, | ||
.files = &.{ | ||
"include_all.cc", | ||
}, | ||
.name = "include_tests", | ||
.dependency = boost_dep, | ||
}); | ||
} | ||
fn buildTests(b: *std.Build, options: struct { | ||
target: std.Build.ResolvedTarget, | ||
optimize: std.builtin.OptimizeMode, | ||
files: []const []const u8, | ||
name: []const u8, | ||
dependency: ?*std.Build.Dependency = null, | ||
}) void { | ||
const exe = b.addExecutable(.{ | ||
.name = options.name, | ||
.target = options.target, | ||
.optimize = options.optimize, | ||
}); | ||
|
||
if (options.dependency) |dep| { | ||
const artifact = dep.artifact("boost"); | ||
for (artifact.root_module.include_dirs.items) |include_dir| { | ||
exe.root_module.include_dirs.append(b.allocator, include_dir) catch unreachable; | ||
} | ||
// exe.linkLibrary(artifact); | ||
} | ||
|
||
for (options.files) |file| { | ||
exe.addCSourceFile(.{ | ||
.file = b.path(file), | ||
}); | ||
} | ||
if (exe.rootModuleTarget().abi != .msvc) { | ||
exe.linkLibCpp(); | ||
} else { | ||
exe.linkLibC(); | ||
} | ||
|
||
b.installArtifact(exe); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.{ | ||
.name = "tests", | ||
.version = "0.0.0", | ||
.dependencies = .{ | ||
.boost = .{ | ||
.path = "..", | ||
}, | ||
}, | ||
.paths = .{""}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <boost/algorithm/algorithm.hpp> | ||
#include <boost/any.hpp> | ||
#include <boost/array.hpp> | ||
#include <boost/asio.hpp> | ||
#include <boost/asio/io_context.hpp> | ||
#include <boost/bind.hpp> | ||
#include <boost/config.hpp> | ||
#include <boost/hana.hpp> | ||
#include <boost/multi_array.hpp> | ||
#include <boost/pfr.hpp> | ||
#include <boost/shared_ptr.hpp> | ||
#include <boost/unordered_map.hpp> | ||
#include <boost/unordered_set.hpp> | ||
#include <boost/variant.hpp> | ||
#include <boost/version.hpp> | ||
|
||
#include <iostream> | ||
|
||
using namespace boost; | ||
|
||
int main() { | ||
std::cout << "Boost version " << BOOST_VERSION / 100000 << "." | ||
<< BOOST_VERSION / 100 % 1000 << "." << BOOST_VERSION % 100 | ||
<< std::endl; | ||
|
||
asio::io_context io_service; | ||
|
||
// Example using boost::variant | ||
variant<int, std::string, double> v; | ||
|
||
v = 42; | ||
std::cout << "Variant contains int: " << get<int>(v) << std::endl; | ||
|
||
v = "Hello, Boost!"; | ||
std::cout << "Variant contains string: " << get<std::string>(v) << std::endl; | ||
|
||
v = 3.14; | ||
std::cout << "Variant contains double: " << get<double>(v) << std::endl; | ||
|
||
// Using a visitor | ||
struct visitor : public static_visitor<void> { | ||
void operator()(int i) const { | ||
std::cout << "Visited int: " << i << std::endl; | ||
} | ||
void operator()(const std::string &s) const { | ||
std::cout << "Visited string: " << s << std::endl; | ||
} | ||
void operator()(double d) const { | ||
std::cout << "Visited double: " << d << std::endl; | ||
} | ||
}; | ||
|
||
v = 100; | ||
apply_visitor(visitor(), v); | ||
|
||
v = "Boost Variant"; | ||
apply_visitor(visitor(), v); | ||
|
||
v = 2.718; | ||
apply_visitor(visitor(), v); | ||
|
||
return 0; | ||
} |