c++ - Exception safety of std::function -
i tried without success find if code throw exception :
std::function<void(void)>f=[]{};
according standard, copy or move constructor of std::function not noexcept. guess lack of noexcept keyword due fact std::function wrap user defined functor object copy or move constructors throw.
in case exception seems unlikely possible @ ?
in case exception seems unlikely possible @ ?
in principle, yes. std::function
have allocate memory store callable object it's initialised with, , if memory allocated dynamically there's possibility of failure.
in practice, in case, no. in words of note in specification, "implementations encouraged avoid use of dynamically allocated memory small callable objects". lambda no captures convertible function pointer, small callable object gets; implementation should store without dynamic allocation. , of course, copying pointer can't throw either.
larger objects (including lambdas many captures) need dynamic allocation, , need copy captured objects or other state, , can't offer no-throw guarantee.
Comments
Post a Comment