Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document DefaultConstructible and CopyConstructible #443

Merged
merged 2 commits into from
Jun 19, 2024
Merged
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
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,14 @@ To write a C++ function that returns a new object that can be garbage-collected
jlcxx::create<Class>(constructor_arg1, ...);
```

This will return the new C++ object wrapped in a `jl_value_t*` that has a finalizer.
This will return the new C++ object wrapped in a `jl_value_t*` that has a
finalizer. The default constructor can be explicitly disabled by specializing
the `DefaultConstructible` type trait, for example:
```c++
namespace jlcxx {
template<> struct DefaultConstructible<Class> : std::false_type { };
}
```

### Copy constructor

Expand All @@ -427,6 +434,14 @@ wvec = cpp_function_returning_vector()
julia_array = copy.(wvec)
```

It can be explicitly disabled for a type by specializing the `CopyConstructible`
type trait, for example:
```c++
namespace jlcxx {
template<> struct CopyConstructible<Class> : std::false_type { };
}
```

### Return values
If a wrapped C++ function returns an object by value, the wrapped object gets a finalizer
and is owned by Julia. The same holds if a smart pointer such as `shared_ptr` (automatically
Expand Down Expand Up @@ -802,6 +817,20 @@ An extra file has to be included to have constant array functionality: `#include

Replacing `make_const_array` in the examples above by `make_julia_array` creates a mutable, regular Julia array with memory owned by C++.

### Returning a Julia array

A Julia-owned `Array` can be created and returned from C++ using the
`jlcxx::Array` class:
```c++
mymodule.method("array", [] () {
jlcxx::Array<int> data{ };
data.push_back(1);
data.push_back(2);
data.push_back(3);

return data;
});
```

## Calling Julia functions from C++

Expand Down
Loading