[libcxx-commits] [libcxx] [libc++] Add a utility to check whether a range is valid (PR #87665)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Apr 6 20:48:42 PDT 2024
================
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <__utility/is_valid_range.h>
+#include <cassert>
+
+#include "test_macros.h"
+
+template <class T>
+TEST_CONSTEXPR_CXX14 void check_type() {
+ {
+ T i = 0;
+ T j = 0;
+ assert(std::__is_valid_range(&i, &i));
+
+ assert(!std::__is_valid_range(&i, &j));
+ assert(!std::__is_valid_range(&i + 1, &i));
+
+ // We detect this one as being a valid range.
+ // Ideally we would detect it as an invalid range, but this may not be implementable.
+ assert(std::__is_valid_range(&i, &i + 1));
----------------
frederick-vs-ja wrote:
Why should `[&i, &i + 1)` be considered invalid? I think [[basic.compound]/3](https://eel.is/c++draft/basic.compound#3.sentence-12) already implies that it's a valid range.
https://github.com/llvm/llvm-project/pull/87665
More information about the libcxx-commits
mailing list