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

Proposal: Use a contructor template #15

Closed
DSchroer opened this issue Dec 23, 2022 · 1 comment · Fixed by #19
Closed

Proposal: Use a contructor template #15

DSchroer opened this issue Dec 23, 2022 · 1 comment · Fixed by #19

Comments

@DSchroer
Copy link
Contributor

DSchroer commented Dec 23, 2022

I know in the past you have opted against using templates on the C++ side. However I was browsing the cxx thread regarding constructors and one of the recent posts recommended a workaround to the problem. Rather than instrument each constructor by itself, create a template like so:

template<typename T, typename... Args>
std::unique_ptr<T> construct(Args... args)
{
  return std::unique_ptr(new T(args...));
}

Then we can just re-use it when binding a new constructor.

What are your thoughts on taking this approach to remove some of the boilerplate?

Original thread:
dtolnay/cxx#280 (comment)

@bschwind
Copy link
Owner

Oh this is nice, I would definitely be in favor of adding this if it reduces boilerplate and doesn't introduce too much complexity.

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 a pull request may close this issue.

2 participants