Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __memory / destruct_n.h
blob2cfb2e4c88ce1a2d2926299abdacc2524e57337a
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___MEMORY_DESTRUCT_N_H
10 #define _LIBCPP___MEMORY_DESTRUCT_N_H
12 #include <__config>
13 #include <__type_traits/integral_constant.h>
14 #include <__type_traits/is_trivially_destructible.h>
15 #include <cstddef>
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
19 #endif
21 _LIBCPP_BEGIN_NAMESPACE_STD
23 struct __destruct_n
25 private:
26 size_t __size_;
28 template <class _Tp>
29 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
30 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
32 template <class _Tp>
33 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
36 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
37 {++__size_;}
38 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
41 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
42 {__size_ = __s;}
43 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
45 public:
46 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
47 : __size_(__s) {}
49 template <class _Tp>
50 _LIBCPP_INLINE_VISIBILITY void __incr() _NOEXCEPT
51 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
53 template <class _Tp>
54 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
55 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
57 template <class _Tp>
58 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
59 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
62 _LIBCPP_END_NAMESPACE_STD
64 #endif // _LIBCPP___MEMORY_DESTRUCT_N_H