Skip to content

embind: Add helper for registering a std::optional type. - #20359

Closed
brendandahl wants to merge 1 commit into
emscripten-core:mainfrom
brendandahl:optional-type
Closed

brendandahl wants to merge 1 commit into
emscripten-core:mainfrom
brendandahl:optional-type

Conversation

@brendandahl

Copy link
Copy Markdown
Collaborator

Fixes #20082

This seems to be a common enough feature request and is slightly tricky to add for users.

#include <emscripten/wire.h>

#ifdef __has_include
#if __has_include(<optional>) && __cplusplus >= 201703L

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emscripten ships its own C++ library, so such checks are likely superfluous.


template<typename T>
class_<std::optional<T>> register_optional(const char* name) {
return class_<std::optional<T>>(name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more idiomatic to map it to T | undefined. E.g. this is what wasm-bindgen does for Option<T>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typescript bindings generation for std::optional types issues

2 participants