Vendored Boost 1.90.0 C++ header-only modules for Swift packages. Uses Swift's C++ interoperability to make Boost headers available to Swift targets.
- Provide 37 Boost C++ header-only modules as individual SwiftPM library products
- Enable Swift/C++ interop consumption of Boost types and algorithms
- Support macOS and Linux (Swift 6.1+, C++17)
- Extract only public headers — no Boost source compilation required
Each Boost module is exposed as an individual SwiftPM library product.
| Category | Modules |
|---|---|
| Algorithms & Ranges | algorithm, foreach, iterator, range |
| Containers | array, container, multi_index, variant, optional, tuple |
| Memory & Pointers | smart_ptr, move |
| Metaprogramming | mp11, mpl, preprocessor, type_traits, type_index |
| Serialization & I/O | serialization, lexical_cast, io |
| Signals & Events | signals2 |
| Utilities | bind, config, core, describe, function, utility |
See Package.swift for the complete list of all 37 modules.
This package uses Swift Package Manager. To add it to your project:
- Go to
File > Add Packages... - Enter the package URL:
https://github.com/21-DOT-DEV/swift-boost - Select the desired version
Add the following to your Package.swift file:
.package(url: "https://github.com/21-DOT-DEV/swift-boost.git", from: "0.1.0"),Then, add the Boost modules you need as dependencies and enable C++ interop:
.target(
name: "MyTarget",
dependencies: [
.product(name: "algorithm", package: "swift-boost"),
.product(name: "optional", package: "swift-boost"),
],
cxxSettings: [
.headerSearchPath("path/to/boost/module/include"),
],
swiftSettings: [
.interoperabilityMode(.Cxx),
]
),Note
This package provides C++ headers, not Swift wrapper APIs. To use Boost types from Swift, you need a C++ bridging header with explicit type aliases and thin wrappers. This is a requirement of Swift/C++ interop — not all C++ patterns import directly.
Create a C++ header that instantiates the Boost templates you need:
#pragma once
#include <boost/algorithm/clamp.hpp>
#include <boost/optional.hpp>
// Expose a concrete template instantiation to Swift
using BoostOptionalInt = boost::optional<int>;
// Thin wrapper: Swift cannot call uninstantiated C++ function templates
inline int boost_clamp(int value, int lo, int hi) {
return boost::algorithm::clamp(value, lo, hi);
}
// Thin wrapper: boost::optional accessors return references,
// which Swift considers interior pointers and blocks by default
inline int boost_optional_value(const boost::optional<int> &opt) {
return opt.get();
}import MyBridgingModule
let clamped = boost_clamp(15, 0, 10) // 10
let opt = BoostOptionalInt(42)
let value = boost_optional_value(opt) // 42Note
For more details on Swift/C++ interop patterns (type aliases for class templates, wrapping function templates, interior pointer limitations), see Swift C++ Interop documentation.
- Swift 6.1+
- C++17
- macOS 13+ or Linux
Sources/
├── algorithm/ # Boost.Algorithm headers (include/boost/algorithm/)
├── optional/ # Boost.Optional headers (include/boost/optional/)
├── variant/ # Boost.Variant headers (include/boost/variant/)
├── ... # 34 more Boost modules
└── BoostTestHelpers/ # C++ bridging header for tests
This project is released under the MIT License. See LICENSE for details.
Boost libraries are distributed under the Boost Software License 1.0.