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

Copy-constructor #14

Closed
matpen opened this issue Apr 21, 2016 · 4 comments
Closed

Copy-constructor #14

matpen opened this issue Apr 21, 2016 · 4 comments
Labels

Comments

@matpen
Copy link

matpen commented Apr 21, 2016

I am a new (since yesterday) user of the library, and first of all I wanted to tank you for such an useful tool.

I am starting now to explore the API and running some tests.
It seems that registration of a class requires a copy-constructor, even if rttr::policy::ctor::as_raw_ptr is used.

Small example attached.
test.zip

This fails to build with a static assert.
Am I missing something?

Thank you in advance!

@matpen
Copy link
Author

matpen commented Apr 21, 2016

Furthermore, running the example from the documentation, it seems that the destructor is never called, and the variant stays valid even after calling destroy().

@acki-m
Copy link
Contributor

acki-m commented Apr 21, 2016

Thanks for bringing up these two issues.
1)
This is an issue in the registration process of the constructor.
When you invoke it like this, then the default policy::ctor::as_object will be used.

rttr::registration::class_<MyStruct>("MyStruct")
            .constructor<>();

I have to think about this how to solve this correctly. So it is not your fault.

Good catch. At the moment you have to retrieve the dtor of the raw type itself.
type::get<Foo>().destroy(var);
However, I can adjust this behaviour, so it will be done implicitly. Then this original code will work without leaking.

This two issues will be fixed in the upcoming release of 0.9.6

@acki-m acki-m added the bug label Apr 21, 2016
@matpen
Copy link
Author

matpen commented Apr 21, 2016

Thank you for your quick reply!
Will be waiting for 0.9.6 then. Keep up the good work!

acki-m added a commit that referenced this issue Apr 28, 2016
Now implicit the raw_type will always be used when retrieving the dtor from a type.
First part of the issue: #14
acki-m added a commit that referenced this issue May 1, 2016
…"as_std_shared_ptr".

This might break some code silently!
Without this change it is not possible to register a constructor
from a class which has a deleted or private copy constructor.

This change will allow now the registration of these kind of classes.

shared_ptr is a valid choice because it has automatic memory management.
Its better here to be explicit and have one rule, instead of doing some hidden magic for this case.

To have the old binding behaviour back, add the policy: 'policy::ctor::as_object'
to every constructor
registration::class_<MyStruct>("MyStruct")
    .constructor<>()
    (
        policy::ctor::as_object
    );

Remark:
When you want to real type of the created instance in the variant, use 'type::get_wrapped_type()'

This will fix issue #14
@acki-m
Copy link
Contributor

acki-m commented May 1, 2016

both issues are now fixed and merged to master in 0.9.6

@acki-m acki-m closed this as completed May 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants