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

value_ptr and abstract types as an element_type #8

Open
flexferrum opened this issue Jun 8, 2019 · 5 comments
Open

value_ptr and abstract types as an element_type #8

flexferrum opened this issue Jun 8, 2019 · 5 comments

Comments

@flexferrum
Copy link

Not sure about direct PR. Decided to make issue for discussion. Looks like current implementation doesn't allow to hold abstract types in value_ptr. Cloner and Deleters implies that it should be possible but value_or method breaks this possibility:

    element_type value_or( U && v ) const
    {
        return has_value() ? value() : static_cast<element_type>(std::forward<U>( v ) );
    }

It implies that element_type should be able to construct from arbitrary type. For abstract types that's wrong expectation. What if "hide" value_or method under enable_if?

@martinmoene
Copy link
Owner

@flexferrum, just to let you know I've noticed your question, looking at it in sparsely scattered time ;)

@flexferrum
Copy link
Author

NP. :)

@flexferrum
Copy link
Author

flexferrum commented Jun 10, 2019

Also it's good to have type requirements for T in value_ptr. Can it be abstract? Can it be incomplete? Copy-constructable, default-constructable etc. And tests for meeting that requirements as well.

UPD: Personally I vote for less possible restrictions.

@martinmoene
Copy link
Owner

Added branch issue-8-abstract.

Not making any progress. After 30+ years there's a sense that C++ might perhaps not be for me ;)

@flexferrum Do you have an idea how to advance this?

@flexferrum
Copy link
Author

After trying the hot-fix on local Jinja2Cpp branch I realized that value_or breaks the value_ptr semantic at all. Actually (in general) you have no way to predict how to create the pointee value properly, that's why you provide Cloner and Deleter params. So, may be it's better to make value_or as an non-class template function. Or introduce something like get_if. Or extend Cloner interface with CreateDefault (???) member.

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

No branches or pull requests

2 participants