A modern C++ metaprogramming library. It provides high level algorithms to manipulate heterogeneous sequences, allows writing type-level computations with a natural syntax, provides tools to introspect user-defined types and much more
Your standard library for metaprogramming
Overview
#include <boost/hana.hpp>
#include <cassert>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
struct Fish { std::string name; };
struct Cat { std::string name; };
struct Dog { std::string name; };
int main() {
// Sequences capable of holding heterogeneous objects, and algorithms
// to manipulate them.
auto animals = hana::make_tuple(Fish{"Nemo"}, Cat{"Garfield"}, Dog{"Snoopy"});
auto names = hana::transform(animals, [](auto a) {
return a.name;
});
assert(hana::reverse(names) == hana::make_tuple("Snoopy", "Garfield", "Nemo"));
// No compile-time information is lost: even if `animals` can't be a
// constant expression because it contains strings, its length is constexpr.
static_assert(hana::length(animals) == 3u, "");
// Computations on types can be performed with the same syntax as that of
// normal C++. Believe it or not, everything is done at compile-time.
auto animal_types = hana::make_tuple(hana::type_c<Fish*>, hana::type_c<Cat&>, hana::type_c<Dog*>);
auto animal_ptrs = hana::filter(animal_types, [](auto a) {
return hana::traits::is_pointer(a);
});
static_assert(animal_ptrs == hana::make_tuple(hana::type_c<Fish*>, hana::type_c<Dog*>), "");
// And many other goodies to make your life easier, including:
// 1. Access to elements in a tuple with a sane syntax.
static_assert(animal_ptrs[0_c] == hana::type_c<Fish*>, "");
static_assert(animal_ptrs[1_c] == hana::type_c<Dog*>, "");
// 2. Unroll loops at compile-time without hassle.
std::string s;
hana::int_c<10>.times([&]{ s += "x"; });
// equivalent to s += "x"; s += "x"; ... s += "x";
// 3. Easily check whether an expression is valid.
// This is usually achieved with complex SFINAE-based tricks.
auto has_name = hana::is_valid([](auto&& x) -> decltype((void)x.name) { });
static_assert(has_name(animals[0_c]), "");
static_assert(!has_name(1), "");
}
Depends (5)
Reviews
Builds
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_17_libc++ |
timestamp |
2025-01-13 05:20:15 UTC (02:04:19 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_17 |
timestamp |
2025-01-13 05:16:27 UTC (02:08:07 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-gcc_13 |
timestamp |
2025-01-12 10:39:14 UTC (20:45:20 hours ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_18_libc++-O3 |
timestamp |
2025-01-12 07:32:07 UTC (23:52:27 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_18_libc++-static_O3 |
timestamp |
2025-01-12 07:31:29 UTC (23:53:05 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_18-static_O3 |
timestamp |
2025-01-12 07:30:07 UTC (23:54:27 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_18_libc++ |
timestamp |
2025-01-12 07:28:33 UTC (23:56:00 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_18-O3 |
timestamp |
2025-01-12 07:27:15 UTC (23:57:19 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_18 |
timestamp |
2025-01-12 07:25:38 UTC (23:58:56 hours ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_18_libc++-static_O3 |
timestamp |
2025-01-12 07:18:11 UTC (01 00:06:23 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_18_libc++ |
timestamp |
2025-01-12 07:09:21 UTC (01 00:15:13 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_18_libc++-O3 |
timestamp |
2025-01-12 07:04:48 UTC (01 00:19:46 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_18-O3 |
timestamp |
2025-01-12 07:01:17 UTC (01 00:23:16 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_18-static_O3 |
timestamp |
2025-01-12 06:58:06 UTC (01 00:26:28 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-clang_18 |
timestamp |
2025-01-12 06:54:08 UTC (01 00:30:26 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-clang_18_llvm_msvc_17.10-static_O2 |
timestamp |
2025-01-11 12:58:59 UTC (01 18:25:35 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-clang_18_llvm_msvc_17.10-O2 |
timestamp |
2025-01-11 12:58:08 UTC (01 18:26:25 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-clang_18_llvm_msvc_17.10 |
timestamp |
2025-01-11 12:57:32 UTC (01 18:27:01 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_fedora_40-gcc_14-bindist |
timestamp |
2025-01-11 12:54:24 UTC (01 18:30:10 days ago) |
result |
warning (update) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-apple-darwin22.5.0 |
tgt config |
macos_13-clang_15.0 |
timestamp |
2025-01-11 12:53:46 UTC (01 18:30:48 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-msvc_17.10-static_O2 |
timestamp |
2025-01-11 12:51:02 UTC (01 18:33:32 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-msvc_17.10 |
timestamp |
2025-01-11 12:50:31 UTC (01 18:34:03 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-msvc_17.8 |
timestamp |
2025-01-11 12:49:50 UTC (01 18:34:44 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-msvc_17.10-O2 |
timestamp |
2025-01-11 12:49:44 UTC (01 18:34:50 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-msvc_17.8-static_O2 |
timestamp |
2025-01-11 12:49:33 UTC (01 18:35:01 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-msvc_17.8-O2 |
timestamp |
2025-01-11 12:48:48 UTC (01 18:35:46 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-gcc_12-bindist |
timestamp |
2025-01-11 12:45:45 UTC (01 18:38:48 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-microsoft-win32-msvc14.3 |
tgt config |
windows_10-clang_17_msvc_msvc_17.10 |
timestamp |
2025-01-11 12:42:08 UTC (01 18:42:26 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-freebsd14.1 |
tgt config |
freebsd_14-clang_18-static_O3 |
timestamp |
2025-01-11 12:38:03 UTC (01 18:46:31 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-freebsd14.1 |
tgt config |
freebsd_14-clang_18-O3 |
timestamp |
2025-01-11 12:37:46 UTC (01 18:46:48 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-freebsd13.3 |
tgt config |
freebsd_13-clang_17 |
timestamp |
2025-01-11 12:37:20 UTC (01 18:47:14 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-freebsd14.1 |
tgt config |
freebsd_14-clang_18 |
timestamp |
2025-01-11 12:37:03 UTC (01 18:47:31 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_17_libc++ |
timestamp |
2025-01-11 12:36:00 UTC (01 18:48:34 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-clang_17 |
timestamp |
2025-01-11 12:34:45 UTC (01 18:49:49 days ago) |
result |
success | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-gcc_14-static_O3 |
timestamp |
2025-01-10 11:12:38 UTC (02 20:11:56 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-gcc_14-ndebug_O3 |
timestamp |
2025-01-10 11:10:56 UTC (02 20:13:38 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_fedora_39-gcc_13-bindist |
timestamp |
2025-01-10 11:10:32 UTC (02 20:14:02 days ago) |
result |
warning (update) | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-gcc_14 |
timestamp |
2025-01-10 11:10:31 UTC (02 20:14:03 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
aarch64-linux-gnu |
tgt config |
linux_debian_12-gcc_14-O3 |
timestamp |
2025-01-10 11:09:55 UTC (02 20:14:39 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-gcc_14-static_O3 |
timestamp |
2025-01-10 11:03:18 UTC (02 20:21:16 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-gcc_14-ndebug_O3 |
timestamp |
2025-01-10 11:01:46 UTC (02 20:22:47 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-gcc_14 |
timestamp |
2025-01-10 11:01:27 UTC (02 20:23:07 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-w64-mingw32 |
tgt config |
windows_10-gcc_13.2_mingw_w64-static_O2 |
timestamp |
2025-01-10 11:00:59 UTC (02 20:23:35 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-gcc_14-O3 |
timestamp |
2025-01-10 11:00:32 UTC (02 20:24:01 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-w64-mingw32 |
tgt config |
windows_10-gcc_13.2_mingw_w64-O2 |
timestamp |
2025-01-10 10:58:45 UTC (02 20:25:49 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-w64-mingw32 |
tgt config |
windows_10-gcc_13.2_mingw_w64 |
timestamp |
2025-01-10 10:56:54 UTC (02 20:27:40 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_ubuntu_24.04-gcc_13-bindist |
timestamp |
2025-01-10 10:53:30 UTC (02 20:31:04 days ago) |
result |
warning (update) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-linux-gnu |
tgt config |
linux_debian_12-gcc_13.1 |
timestamp |
2025-01-10 10:39:19 UTC (02 20:45:15 days ago) |
result |
warning (update) | warning (test-installed) | log | rebuild |
toolchain |
public-0.17.0 |
target |
x86_64-apple-darwin23.5.0 |
tgt config |
macos_14-clang_15.0 |
result |
unbuilt |
toolchain |
public-0.17.0 |
target |
x86_64-apple-darwin23.5.0 |
tgt config |
macos_14-clang_15.0-O3 |
result |
unbuilt |
toolchain |
public-0.17.0 |
target |
x86_64-apple-darwin23.5.0 |
tgt config |
macos_14-clang_15.0-static_O3 |
result |
unbuilt |
target |
x86_64-apple-darwin23.5.0 |
tgt config |
macos_14-gcc_14_homebrew |
result |
excluded (https://github) |
target |
x86_64-apple-darwin23.5.0 |
tgt config |
macos_14-gcc_14_homebrew-O3 |
result |
excluded (https://github) |
target |
x86_64-apple-darwin23.5.0 |
tgt config |
macos_14-gcc_14_homebrew-static_O3 |
result |
excluded (https://github) |