1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// UNSUPPORTED: c++98, c++03, c++11, c++14
11
12// <memory>
13
14// template <class ForwardIt>
15// void destroy(ForwardIt, ForwardIt);
16
17#include <memory>
18#include <cstdlib>
19#include <cassert>
20
21#include "test_macros.h"
22#include "test_iterators.h"
23
24struct Counted {
25  static int count;
26  static void reset() { count = 0; }
27  Counted() { ++count; }
28  Counted(Counted const&) { ++count; }
29  ~Counted() { --count; }
30  friend void operator&(Counted) = delete;
31};
32int Counted::count = 0;
33
34int main()
35{
36    using It = forward_iterator<Counted*>;
37    const int N = 5;
38    alignas(Counted) char pool[sizeof(Counted)*N] = {};
39    Counted* p = (Counted*)pool;
40    std::uninitialized_fill(p, p+N, Counted());
41    assert(Counted::count == 5);
42    std::destroy(p, p+1);
43    p += 1;
44    assert(Counted::count == 4);
45    std::destroy(It(p), It(p + 4));
46    assert(Counted::count == 0);
47}
48