Hi, Am 11.11.2017 02:53, schrieb Jonathan Biggar via Boost:
I'm building a small "transactional" library I'd like to contribute to boost where certain API calls are constrained to only be valid if the transaction is still "in-progress".
I think there is some room of improvement on the API, whenever an issue like that arises. For a transactional library I'd try and create an interface, where the lifetime of the transaction object is in line with the transaction being "in progress". The destructor would simply roll back, if the transaction has not been moved from, while a commit() function that takes an rvalue reference to a transaction commits it. The compiler would warn, if the transaction object is used after it has been moved from. Something like this: ---- // begin transaction auto t = transaction{transactional_memory}; // do something auto bar = t.find_foo("bar"); // might throw bar.extend("blabla"); // will commit if extend() did not throw, rollback otherwise. // Note, that t is moved into the parameter of commit here. commit(t); // undefined behaviour, compiler will warn. auto lala = t.find_foo("lala"); // will do move assignment. t is usable again, // but now refers to the other transaction. t = get_another_transaction_somehow(); // now this is safe, but will of course use the new transaction. auto lala = t.find_foo("lala"); ---- But maybe I just misunderstood, what you are trying to do. Christof