diff --git a/include/boost/compat/move_only_function.hpp b/include/boost/compat/move_only_function.hpp index 5511b52..d307a00 100644 --- a/include/boost/compat/move_only_function.hpp +++ b/include/boost/compat/move_only_function.hpp @@ -435,6 +435,22 @@ struct move_only_function_base { } + template + void init_object( std::false_type /* use_sbo */, CArgs&& ...args ) + { + s_.pobj_ = new VT( std::forward( args )... ); + invoke_ = &mo_invoke_object_holder::invoke_object; + manager_ = &manage_object; + } + + template + void init_object( std::true_type /* use_sbo */, CArgs&& ...args ) + { + new( s_.addr() ) VT( std::forward( args )... ); + invoke_ = &mo_invoke_local_holder::invoke_local; + manager_ = &manage_local; + } + template void init( std::false_type /* is_function */, CArgs&& ...args ) { @@ -444,18 +460,7 @@ struct move_only_function_base return; } - if( !storage::use_sbo() ) - { - s_.pobj_ = new VT( std::forward( args )... ); - invoke_ = &mo_invoke_object_holder::invoke_object; - manager_ = &manage_object; - } - else - { - new( s_.addr() ) VT( std::forward( args )... ); - invoke_ = &mo_invoke_local_holder::invoke_local; - manager_ = &manage_local; - } + init_object( std::integral_constant()>{}, std::forward( args )... ); } template