Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-26 09:34:39

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file corecel/sys/ScopeExit.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <utility>
0010 
0011 #include "corecel/Macros.hh"
0012 
0013 namespace celeritas
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Call a function when this object is destroyed (at end of scope).
0018  */
0019 template<class F>
0020 class ScopeExit
0021 {
0022   public:
0023     //! Construct with functor
0024     ScopeExit(F&& func) : func_{std::forward<F>(func)} {}
0025 
0026     //! Call functor on destruction
0027     ~ScopeExit() { func_(); }
0028 
0029     CELER_DELETE_COPY_MOVE(ScopeExit);
0030 
0031   private:
0032     F func_;
0033 };
0034 
0035 template<class F>
0036 ScopeExit(F&& func) -> ScopeExit<F>;
0037 
0038 //---------------------------------------------------------------------------//
0039 }  // namespace celeritas