The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
finally.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
13#include <utility>
14//
15// make it possible to execute an action at the exit of a scope
16//
17// auto f = finally( [](){ std::cout << "end of scope!" << std::endl; } );
18//
19// the above will execute the provided callable when f goes out of scope,
20// i.e. the 'current' scope ends.
21
22template <typename F>
24 F act;
25 final_action( F&& act ) : act{ std::move( act ) } {}
26 final_action( final_action&& ) = default;
28};
29
30template <typename F>
31final_action<F> finally( F&& act ) {
32 return { std::forward<F>( act ) };
33}
STL namespace.
final_action(final_action &&)=default
final_action(F &&act)
Definition finally.h:25
~final_action()
Definition finally.h:27