call_once Function

call_once Function


Provides a mechanism for calling a specified callable object exactly once during execution.

template<class Callable, class... Args>
   void call_once(once_flag& Flag,
      Callable F&&, Args&&... A);


A once_flag object that ensures that the callable object is only called once.


A callable object.


An argument list.

If Flag is not valid, the function throws a system_error that has an error code of invalid_argument. Otherwise, the template function uses its Flag argument to ensure that it calls F(A...) successfully exactly once, regardless of how many times the template function is called. If F(A...) exits by throwing an exception, the call was not successful.


Header: mutex

Namespace: std

© 2015 Microsoft