-
Notifications
You must be signed in to change notification settings - Fork 448
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
boost::optional<T> as properties #29
Comments
Thank you for using RTTR. Regarding the question of the naming you can set the name via
boost::optional is for my point of view a wrapper, so you can provide a wrapper mapper:
Regarding 2) |
Thanks for your answer. I can't use the wrapper_mapper unfortunately because at some point, some code seems to call get() when the value is not initialized. But I can use a succession of ifs, I don't have too many types anyway. |
I thinking there is a way to register the "is_initialized" method from the base class and invoke it, when you have a derived instance. So you don't need to create your own |
Thanks, indeed, registering the "is_initialized" method would be a much better solution! |
@MicBe This is actually a pretty nice feature, thanks for the suggestion. 👍 I will merge it now to master |
Thank you! I love this lib.
…On Fri, Mar 31, 2017 at 1:06 PM, acki-m ***@***.***> wrote:
Closed #29 <#29> via 5a90984
<5a90984>
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#29 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AHtMportGgLEWt1y2mHL8ve0IKKNP1wuks5rrTKtgaJpZM4LNhL3>
.
|
Hi,
First of all, great library! I have some questions about it.
I have classes with members like this:
I have declared those members as properties of the class and I can access them correctly.
I have two problems:
1- During the looping over the properties of
User
, how can I know which one is a boost::optional (without using type name, which is not portable)?My solution for now is to add metadata manually to each boost::optional property to indicate this, but I have a feeling this might not be the best solution.
2- Before getting the underlying value of the boost::optional property, I need to call is_initialized() on the property(which is of type boost::optional) to make sure the value is valid (otherwise, it's undefined behavior). The problem is that in order to call that method, I need to have an instance of boost::optional which I can't because Type is not known until runtime.
Unless I do a ton of ifs for each type(in this case, one for string, one for Mailbox and one for vector), I don't see how I can call is_initialized() for all types without typing them in the source code like this:
Is there something I'm missing or there is no easy solution to this?
The text was updated successfully, but these errors were encountered: