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 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++98, c++03, c++11, c++14
10 
11 // <memory>
12 
13 // template <class ForwardIt>
14 // void destroy(ForwardIt, ForwardIt);
15 
16 #include <memory>
17 #include <cstdlib>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "test_iterators.h"
22 
23 struct Counted {
24   static int count;
25   static void reset() { count = 0; }
26   Counted() { ++count; }
27   Counted(Counted const&) { ++count; }
28   ~Counted() { --count; }
29   friend void operator&(Counted) = delete;
30 };
31 int Counted::count = 0;
32 
33 int main(int, char**)
34 {
35     using It = forward_iterator<Counted*>;
36     const int N = 5;
37     alignas(Counted) char pool[sizeof(Counted)*N] = {};
38     Counted* p = (Counted*)pool;
39     std::uninitialized_fill(p, p+N, Counted());
40     assert(Counted::count == 5);
41     std::destroy(p, p+1);
42     p += 1;
43     assert(Counted::count == 4);
44     std::destroy(It(p), It(p + 4));
45     assert(Counted::count == 0);
46 
47   return 0;
48 }
49