aboutsummaryrefslogtreecommitdiff
path: root/libcxx/test/libcxx-03/utilities/is_pointer_in_range.pass.cpp
blob: 6c60147adfdf495ab96c4fe3c71f6c4d8075ff8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <__cxx03/__utility/is_pointer_in_range.h>
#include <cassert>

#include "test_macros.h"

template <class T, class U>
TEST_CONSTEXPR_CXX14 void test_cv_quals() {
  T i = 0;
  U j = 0;
  assert(!std::__is_pointer_in_range(&i, &i, &i));
  assert(std::__is_pointer_in_range(&i, &i + 1, &i));
  assert(!std::__is_pointer_in_range(&i, &i + 1, &j));

#if TEST_STD_VER >= 20
  {
    T* arr1 = new int[4]{1, 2, 3, 4};
    U* arr2 = new int[4]{5, 6, 7, 8};

    assert(!std::__is_pointer_in_range(arr1, arr1 + 4, arr2));
    assert(std::__is_pointer_in_range(arr1, arr1 + 4, arr1 + 3));
    assert(!std::__is_pointer_in_range(arr1, arr1, arr1 + 3));

    delete[] arr1;
    delete[] arr2;
  }
#endif
}

TEST_CONSTEXPR_CXX14 bool test() {
  test_cv_quals<int, int>();
  test_cv_quals<const int, int>();
  test_cv_quals<int, const int>();
  test_cv_quals<const int, const int>();
  test_cv_quals<volatile int, int>();
  test_cv_quals<int, volatile int>();
  test_cv_quals<volatile int, volatile int>();

  return true;
}

int main(int, char**) {
  test();
#if TEST_STD_VER >= 14
  static_assert(test(), "");
#endif

  return 0;
}