How to guarantee order of argument evaluation when calling a function object?

前端 未结 4 1734
深忆病人
深忆病人 2020-11-27 16:41

The answers to the question on how to avoid undefined execution order for the constructors when using std::make_tuple led to a discussion during which I learned that the ord

4条回答
  •  [愿得一人]
    2020-11-27 17:21

    Can the guarantees to constructors be used to build a function call facility ("function_apply()") with an ordering guarantee for the evaluation of arguments?

    Yes, the Fit library already does this with fit::apply_eval:

     auto result = fit::apply_eval(f, [&]{ return foo() }, [&]{ return bar(); });
    

    So foo() will be called before bar().

提交回复
热议问题