Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions include/jk/value.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once
#include <jk/config.hpp>

#include <cstddef>
#include <utility>

namespace jk
{
struct value;
Expand Down Expand Up @@ -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 <typename F>
inline decltype(auto) visit(F&& f, value& self)
{
return config::variant_ns::visit(std::forward<F>(f), self.v);
}
template <typename F>
inline decltype(auto) visit(F&& f, const value& self)
{
return config::variant_ns::visit(std::forward<F>(f), self.v);
}
template <typename F>
inline decltype(auto) visit(F&& f, value&& self)
{
return config::variant_ns::visit(std::forward<F>(f), std::move(self.v));
}

// clang-format on
}