On 11/27/23 04:50, Klemens Morgenstern via Boost wrote:
The BOOST_SCOPE_FINAL is limited to C++17 because the correct way is to use deduction guides, and that would be perfectly fine for me. However, it would be quite simple to add this functionality to C++11 like so:
struct no_one_likes_expression_templates { template<typename Func> auto operator%(Func && func) -> decltype(boost::scope::make_scope_exit(std::declval<Func>())) { return boost::scope::make_scope_exit(std::forward<Func>(func)); } };
#define BOOST_SCOPE_FINAL_11 \ auto BOOST_JOIN(_boost_scope_final_, BOOST_SCOPE_DETAIL_UNIQUE_VAR_TAG) = no_one_likes_expression_templates{} %
This would be a misnomer as it would create a scope_exit instead of scope_final. You can't create a scope_final this way because it isn't moveable, and RVO is optional in C++11. I can provide C++11 macros a-la BOOST_SCOPE_FINAL for creating scope_exit/fail/success (e.g. BOOST_SCOPE_EXIT/FAIL/SUCCESS_GUARD), but I don't see a way to make BOOST_SCOPE_FINAL C++11.