From 2caf7f7fca3769adb52f9a086884f478939896b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Wed, 17 Jun 2026 08:06:02 -0400 Subject: [PATCH] value: model the variant_ish concept (index/valueless/visit) jk::value wraps the variant in a member, so it satisfied none of the variant concepts used by generic consumers (e.g. Avendish's back-end bindings): value.index()/visit(f, value) didn't resolve. Forward the variant interface (index, valueless_by_exception, and an ADL visit on the wrapped member) so jk::value is usable directly as a variant value without exposing .v at every call site. Co-Authored-By: Claude Opus 4.7 --- include/jk/value.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/jk/value.hpp b/include/jk/value.hpp index 3974041..289e82c 100644 --- a/include/jk/value.hpp +++ b/include/jk/value.hpp @@ -1,6 +1,9 @@ #pragma once #include +#include +#include + namespace jk { struct value; @@ -63,7 +66,31 @@ struct value operator variant&&() && noexcept { return std::move(v); } bool operator==(const value& other) const noexcept = default; + + // Model avnd::variant_ish: the Avendish back-end bindings (pd / max / wasm) + // treat a value output as a variant (concept check + unqualified visit). Expose + // the variant interface so jk::value is usable directly, without libossia. + std::size_t index() const noexcept { return v.index(); } + bool valueless_by_exception() const noexcept { return v.valueless_by_exception(); } }; +// ADL hook for the bindings' unqualified visit(f, value): forward to the +// configured variant's visit on the wrapped member. +template +inline decltype(auto) visit(F&& f, value& self) +{ + return config::variant_ns::visit(std::forward(f), self.v); +} +template +inline decltype(auto) visit(F&& f, const value& self) +{ + return config::variant_ns::visit(std::forward(f), self.v); +} +template +inline decltype(auto) visit(F&& f, value&& self) +{ + return config::variant_ns::visit(std::forward(f), std::move(self.v)); +} + // clang-format on }