-
Notifications
You must be signed in to change notification settings - Fork 1
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
Hf prewrite pause #19
base: skycleaver
Are you sure you want to change the base?
Conversation
…ant for pre write actions
I wasn't quite able to use
Apart from this, it seems to work. |
Work now with unique_ptrs. The code aborts now without an active exception.
|
I am confused. We previously had the handler instances created on stack like this: IBWriterType ib_handler(config, "ib", create_stream_callback_ib); which was fine to do because it is not invalidated until the entire pipeline is run. Now the code has changed it to unique pointers in the declaration but still uses We should either change all subsequent declarations to use unique_ptrs or not use them at all. |
You can't conditionally allocate non-copyable, non-moveable types on the stack. |
Ewan and I discussed and I get it now, I am going to merge skycleaver to pipeline_dev now, and then pull this into skycleaver, as part of the next roll off of features. |
Btw, I realised that my previous statement is not quite right. Since C++17 you can do this using immediately invoked function expressions (IIFEs). Basically a lambda that is called at construction. C++17 and above guarantee that return value optimisation (RVO) is used in these circumstances, so the compiler will elide the function call. struct NonCopyableNonMovable {
NonCopyableNonMovable(int x) { std::cout << "Constructor called with x: " << x << std::endl; }
NonCopyableNonMovable(int x, int y) { std::cout << "Constructor called with x: " << x << ", y: " << y << std::endl; }
// Delete copy/move constructors
NonCopyableNonMovable(const NonCopyableNonMovable&) = delete;
NonCopyableNonMovable(NonCopyableNonMovable&&) = delete;
NonCopyableNonMovable& operator=(const NonCopyableNonMovable&) = delete;
NonCopyableNonMovable& operator=(NonCopyableNonMovable&&) = delete;
~NonCopyableNonMovable() = default;
};
int main() {
bool condition = true; // Some condition
NonCopyableNonMovable obj = [&]() -> NonCopyableNonMovable {
if (condition) {
return NonCopyableNonMovable{42}; // Constructor for one argument
} else {
return NonCopyableNonMovable{10, 20}; // Constructor for two arguments
}
}();
// Use obj here...
return 0;
} This can be used instead of the unique_ptr if desired (doesn't materially change anything, just means that the object is stack allocated which is a bit faster). |
As requested, I create the pull request into the skycleaver branch.