brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · d3bd7cc Raw
46 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// ADDITIONAL_COMPILE_FLAGS(clang): -Wprivate-header10 11#include <__cxx03/__iterator/aliasing_iterator.h>12#include <cassert>13 14struct NonTrivial {15  int i_;16 17  NonTrivial(int i) : i_(i) {}18  NonTrivial(const NonTrivial& other) : i_(other.i_) {}19 20  NonTrivial& operator=(const NonTrivial& other) {21    i_ = other.i_;22    return *this;23  }24 25  ~NonTrivial() {}26};27 28int main(int, char**) {29  {30    NonTrivial arr[] = {1, 2, 3, 4};31    std::__aliasing_iterator<NonTrivial*, int> iter(arr);32 33    assert(*iter == 1);34    assert(iter[0] == 1);35    assert(iter[1] == 2);36    ++iter;37    assert(*iter == 2);38    assert(iter[-1] == 1);39    assert(iter.__base() == arr + 1);40    assert(iter == iter);41    assert(iter != (iter + 1));42  }43 44  return 0;45}46