diff --git a/examples/types.cpp b/examples/types.cpp index 89983d8..68c3b6f 100644 --- a/examples/types.cpp +++ b/examples/types.cpp @@ -367,6 +367,10 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& types) types.set_const("EnumClassBlue", EnumClass::blue); types.method("check_red", [] (const EnumClass c) { return c == EnumClass::red; }); + static const EnumClass stored_blue = EnumClass::blue; + types.method("check_enum_byref", [] (const EnumClass& c) { return c == EnumClass::red; }); + types.set_const("StoredBlue", stored_blue); + types.add_type("Foo") .constructor>() .method("name", [](Foo& f) { return f.name; }) diff --git a/include/jlcxx/module.hpp b/include/jlcxx/module.hpp index 933d994..ef83521 100644 --- a/include/jlcxx/module.hpp +++ b/include/jlcxx/module.hpp @@ -629,12 +629,13 @@ class JLCXX_API Module template void set_const(const std::string& name, T&& value) { - static_assert(IsMirroredType::type>::value, "set_const can only be applied to IsMirrored types (e.g. numbers or standard layout structs)"); + using plain_type = remove_const_ref; + static_assert(IsMirroredType::value, "set_const can only be applied to IsMirrored types (e.g. numbers or standard layout structs)"); if(get_constant(name) != nullptr) { throw std::runtime_error("Duplicate registration of constant " + name); } - set_constant(name, box(value)); + set_constant(name, box(value)); } std::string name() const