Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:07

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___UTILITY_SCOPE_GUARD_H
0011 #define _LIBCPP___UTILITY_SCOPE_GUARD_H
0012 
0013 #include <__assert>
0014 #include <__config>
0015 #include <__utility/move.h>
0016 
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 #  pragma GCC system_header
0019 #endif
0020 
0021 _LIBCPP_PUSH_MACROS
0022 #include <__undef_macros>
0023 
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025 
0026 template <class _Func>
0027 class __scope_guard {
0028   _Func __func_;
0029 
0030 public:
0031   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __scope_guard(_Func __func) : __func_(std::move(__func)) {}
0032   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__scope_guard() { __func_(); }
0033 
0034   __scope_guard(const __scope_guard&)            = delete;
0035   __scope_guard& operator=(const __scope_guard&) = delete;
0036   __scope_guard& operator=(__scope_guard&&)      = delete;
0037 
0038 // C++14 doesn't have mandatory RVO, so we have to provide a declaration even though no compiler will ever generate
0039 // a call to the move constructor.
0040 #if _LIBCPP_STD_VER <= 14
0041   __scope_guard(__scope_guard&&);
0042 #else
0043   __scope_guard(__scope_guard&&) = delete;
0044 #endif
0045 };
0046 
0047 template <class _Func>
0048 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __scope_guard<_Func> __make_scope_guard(_Func __func) {
0049   return __scope_guard<_Func>(std::move(__func));
0050 }
0051 
0052 _LIBCPP_END_NAMESPACE_STD
0053 
0054 _LIBCPP_POP_MACROS
0055 
0056 #endif // _LIBCPP___UTILITY_SCOPE_GUARD_H