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

Make std::inplace_function a specialization of std::basic_function #114

Open
carlcook opened this issue Oct 11, 2017 · 2 comments
Open

Make std::inplace_function a specialization of std::basic_function #114

carlcook opened this issue Oct 11, 2017 · 2 comments

Comments

@carlcook
Copy link
Member

carlcook commented Oct 11, 2017

This was feedback I received from Louis Dionne during the SG14 meeting at CppCon.

The idea is that with Folly (being a unique function), there might actually be lots of use cases of different storage types (and other behaviours), and then we will get an explosion of new types (e.g. std function, move-only function, inplace function). Maybe it is best to do what std::basic_string does, where Traits are used to provide the implementation details.

So basically the standard focuses on basic_function, and then inplace function is a second proposal that builds on basic function, providing traits where memory allocation is inplace.

@carlcook
Copy link
Member Author

Here's the feedback that Louis gave (check out the example... it's pretty cool!)

ldionne [9:50 AM]
@U3PBVV546 Check this out: https://github.com/ldionne/dyno/blob/1386582bd63c493ba5aa77d9d07b7b482f35726e/example/function.cpp#L39

You can also control what gets in the vtable (and how the vtable is implemented), which solves the problem for unique_function at the same time (just don’t use dyno::CopyConstructible).

@Quuxplusone
Copy link
Contributor

Today I played around with a basic_any that would enable creating specializations such as

using any = basic_any<32, alignof(std::max_align_t), std::allocator<void>>;

template<size_t Size, size_t Align>
using inplace_any = basic_any<Size, Align, inplace_allocator<void>>;

template<size_t Size, size_t Align>
using constexpr_any = basic_any<0, 0, constexpr_allocator<void>>;

You can find my current code here. The constexpr stuff still doesn't quite work; but I think that maybe it can be made to work if I just roll back the m_behaviors function optimization and go with plain old base-class-and-vtable type erasure.

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