You've already forked Zygisk-Assistant
mirror of
https://github.com/snake-4/Zygisk-Assistant.git
synced 2025-09-06 06:37:02 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr basic_string_view& operator=(const basic_string_view &) noexcept = default;
|
||||
|
||||
#include <string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template<typename T>
|
||||
#if TEST_STD_VER > 11
|
||||
constexpr
|
||||
#endif
|
||||
bool test (T sv0)
|
||||
{
|
||||
T sv1;
|
||||
sv1 = sv0;
|
||||
// We can't just say "sv0 == sv1" here because string_view::compare
|
||||
// isn't constexpr until C++17, and we want to support back to C++14
|
||||
return sv0.size() == sv1.size() && sv0.data() == sv1.data();
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
|
||||
assert( test<std::string_view> ( "1234"));
|
||||
#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
|
||||
assert( test<std::u8string_view> (u8"1234"));
|
||||
#endif
|
||||
#if TEST_STD_VER >= 11
|
||||
assert( test<std::u16string_view> ( u"1234"));
|
||||
assert( test<std::u32string_view> ( U"1234"));
|
||||
#endif
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
assert( test<std::wstring_view> ( L"1234"));
|
||||
#endif
|
||||
|
||||
#if TEST_STD_VER > 11
|
||||
static_assert( test<std::string_view> ({ "abc", 3}), "");
|
||||
# if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
|
||||
static_assert( test<std::u8string_view> ({u8"abc", 3}), "");
|
||||
# endif
|
||||
static_assert( test<std::u16string_view> ({ u"abc", 3}), "");
|
||||
static_assert( test<std::u32string_view> ({ U"abc", 3}), "");
|
||||
# ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
static_assert( test<std::wstring_view> ({ L"abc", 3}), "");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr basic_string_view () noexcept;
|
||||
|
||||
#include <string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template<typename T>
|
||||
void test () {
|
||||
#if TEST_STD_VER > 11
|
||||
{
|
||||
ASSERT_NOEXCEPT(T());
|
||||
|
||||
constexpr T sv1;
|
||||
static_assert ( sv1.size() == 0, "" );
|
||||
static_assert ( sv1.empty(), "");
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
T sv1;
|
||||
assert ( sv1.size() == 0 );
|
||||
assert ( sv1.empty());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test<std::string_view> ();
|
||||
test<std::u16string_view> ();
|
||||
#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
|
||||
test<std::u8string_view> ();
|
||||
#endif
|
||||
test<std::u32string_view> ();
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
test<std::wstring_view> ();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template <class It, class End>
|
||||
// constexpr basic_string_view(It begin, End end)
|
||||
|
||||
#include <string_view>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
|
||||
#include "make_string.h"
|
||||
#include "test_iterators.h"
|
||||
|
||||
template<class It, class Sentinel, class CharT>
|
||||
constexpr void test_construction(std::basic_string_view<CharT> val) {
|
||||
auto sv = std::basic_string_view<CharT>(It(val.data()), Sentinel(It(val.data() + val.size())));
|
||||
assert(sv.data() == val.data());
|
||||
assert(sv.size() == val.size());
|
||||
}
|
||||
|
||||
template<class CharT>
|
||||
constexpr void test_with_char() {
|
||||
const auto val = MAKE_STRING_VIEW(CharT, "test");
|
||||
test_construction<CharT*, CharT*>(val);
|
||||
test_construction<CharT*, const CharT*>(val);
|
||||
test_construction<const CharT*, CharT*>(val);
|
||||
test_construction<const CharT*, sized_sentinel<const CharT*>>(val);
|
||||
test_construction<contiguous_iterator<const CharT*>, contiguous_iterator<const CharT*>>(val);
|
||||
test_construction<contiguous_iterator<const CharT*>, sized_sentinel<contiguous_iterator<const CharT*>>>(val);
|
||||
}
|
||||
|
||||
constexpr bool test() {
|
||||
test_with_char<char>();
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
test_with_char<wchar_t>();
|
||||
#endif
|
||||
test_with_char<char8_t>();
|
||||
test_with_char<char16_t>();
|
||||
test_with_char<char32_t>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
template<class CharT>
|
||||
struct ThrowingSentinel {
|
||||
friend bool operator==(const CharT*, ThrowingSentinel) noexcept { return true; }
|
||||
friend std::iter_difference_t<const CharT*> operator-(const CharT*, ThrowingSentinel) noexcept { return {}; }
|
||||
friend std::iter_difference_t<const CharT*> operator-(ThrowingSentinel, const CharT*) { throw 42; }
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
void test_throwing() {
|
||||
auto val = MAKE_STRING_VIEW(CharT, "test");
|
||||
try {
|
||||
(void)std::basic_string_view<CharT>(val.data(), ThrowingSentinel<CharT>());
|
||||
assert(false);
|
||||
} catch (int i) {
|
||||
assert(i == 42);
|
||||
}
|
||||
}
|
||||
|
||||
void test_throwing() {
|
||||
test_throwing<char>();
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
test_throwing<wchar_t>();
|
||||
#endif
|
||||
test_throwing<char8_t>();
|
||||
test_throwing<char16_t>();
|
||||
test_throwing<char32_t>();
|
||||
}
|
||||
#endif
|
||||
|
||||
static_assert( std::is_constructible_v<std::string_view, const char*, char*>);
|
||||
static_assert( std::is_constructible_v<std::string_view, char*, const char*>);
|
||||
static_assert(!std::is_constructible_v<std::string_view, char*, void*>); // not a sentinel
|
||||
static_assert(!std::is_constructible_v<std::string_view, signed char*, signed char*>); // wrong char type
|
||||
static_assert(!std::is_constructible_v<std::string_view, random_access_iterator<char*>, random_access_iterator<char*>>); // not contiguous
|
||||
static_assert( std::is_constructible_v<std::string_view, contiguous_iterator<char*>, contiguous_iterator<char*>>);
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
static_assert(test());
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
test_throwing();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr basic_string_view(const _CharT* _s)
|
||||
// : __data (_s), __size(_Traits::length(_s)) {}
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "constexpr_char_traits.h"
|
||||
|
||||
template<typename CharT>
|
||||
size_t StrLen ( const CharT *s ) {
|
||||
size_t retVal = 0;
|
||||
while ( *s != 0 ) { ++retVal; ++s; }
|
||||
return retVal;
|
||||
}
|
||||
|
||||
template<typename CharT>
|
||||
void test ( const CharT *s ) {
|
||||
typedef std::basic_string_view<CharT> SV;
|
||||
// I'd love to do this, but it would require traits::length() to be noexcept
|
||||
// LIBCPP_ASSERT_NOEXCEPT(SV(s));
|
||||
|
||||
SV sv1 ( s );
|
||||
assert ( sv1.size() == StrLen( s ));
|
||||
assert ( sv1.data() == s );
|
||||
}
|
||||
|
||||
|
||||
int main(int, char**) {
|
||||
|
||||
test ( "QBCDE" );
|
||||
test ( "A" );
|
||||
test ( "" );
|
||||
|
||||
test ( L"QBCDE" );
|
||||
test ( L"A" );
|
||||
test ( L"" );
|
||||
|
||||
#if TEST_STD_VER >= 11
|
||||
test ( u"QBCDE" );
|
||||
test ( u"A" );
|
||||
test ( u"" );
|
||||
|
||||
test ( U"QBCDE" );
|
||||
test ( U"A" );
|
||||
test ( U"" );
|
||||
#endif
|
||||
|
||||
#if TEST_STD_VER > 11
|
||||
{
|
||||
constexpr std::basic_string_view<char, constexpr_char_traits<char>> sv1 ( "ABCDE" );
|
||||
static_assert ( sv1.size() == 5, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
|
||||
|
||||
// <string_view>
|
||||
|
||||
// constexpr basic_string_view(const _CharT* _s, size_type _len)
|
||||
// : __data (_s), __size(_len) {}
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template<typename CharT>
|
||||
void test ( const CharT *s, size_t sz ) {
|
||||
{
|
||||
typedef std::basic_string_view<CharT> SV;
|
||||
LIBCPP_ASSERT_NOEXCEPT(SV(s, sz));
|
||||
|
||||
SV sv1 ( s, sz );
|
||||
assert ( sv1.size() == sz );
|
||||
assert ( sv1.data() == s );
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
|
||||
test ( "QBCDE", 5 );
|
||||
test ( "QBCDE", 2 );
|
||||
test ( "", 0 );
|
||||
#if TEST_STD_VER > 11
|
||||
{
|
||||
constexpr const char *s = "QBCDE";
|
||||
constexpr std::basic_string_view<char> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
|
||||
test ( L"QBCDE", 5 );
|
||||
test ( L"QBCDE", 2 );
|
||||
test ( L"", 0 );
|
||||
#if TEST_STD_VER > 11
|
||||
{
|
||||
constexpr const wchar_t *s = L"QBCDE";
|
||||
constexpr std::basic_string_view<wchar_t> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TEST_STD_VER >= 11
|
||||
test ( u"QBCDE", 5 );
|
||||
test ( u"QBCDE", 2 );
|
||||
test ( u"", 0 );
|
||||
#if TEST_STD_VER > 11
|
||||
{
|
||||
constexpr const char16_t *s = u"QBCDE";
|
||||
constexpr std::basic_string_view<char16_t> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
|
||||
test ( U"QBCDE", 5 );
|
||||
test ( U"QBCDE", 2 );
|
||||
test ( U"", 0 );
|
||||
#if TEST_STD_VER > 11
|
||||
{
|
||||
constexpr const char32_t *s = U"QBCDE";
|
||||
constexpr std::basic_string_view<char32_t> sv1 ( s, 2 );
|
||||
static_assert ( sv1.size() == 2, "" );
|
||||
static_assert ( sv1.data() == s, "" );
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template <class Range>
|
||||
// constexpr basic_string_view(Range&& range);
|
||||
|
||||
#include <string_view>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <ranges>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "constexpr_char_traits.h"
|
||||
#include "make_string.h"
|
||||
#include "test_iterators.h"
|
||||
#include "test_range.h"
|
||||
|
||||
template<class CharT>
|
||||
constexpr void test() {
|
||||
auto data = MAKE_STRING_VIEW(CharT, "test");
|
||||
std::array<CharT, 4> arr;
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
arr[i] = data[i];
|
||||
}
|
||||
auto sv = std::basic_string_view<CharT>(arr);
|
||||
|
||||
ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view<CharT>);
|
||||
assert(sv.size() == arr.size());
|
||||
assert(sv.data() == arr.data());
|
||||
}
|
||||
|
||||
constexpr bool test() {
|
||||
test<char>();
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
test<wchar_t>();
|
||||
#endif
|
||||
test<char8_t>();
|
||||
test<char16_t>();
|
||||
test<char32_t>();
|
||||
|
||||
{
|
||||
struct NonConstConversionOperator {
|
||||
const char* data_ = "test";
|
||||
constexpr const char* begin() const { return data_; }
|
||||
constexpr const char* end() const { return data_ + 4; }
|
||||
constexpr operator std::basic_string_view<char>() { return "NonConstConversionOp"; }
|
||||
};
|
||||
|
||||
NonConstConversionOperator nc;
|
||||
std::string_view sv = nc;
|
||||
assert(sv == "NonConstConversionOp");
|
||||
static_assert(!std::is_constructible_v<std::string_view,
|
||||
const NonConstConversionOperator&>); // conversion operator is non-const
|
||||
}
|
||||
|
||||
{
|
||||
struct ConstConversionOperator {
|
||||
const char* data_ = "test";
|
||||
constexpr const char* begin() const { return data_; }
|
||||
constexpr const char* end() const { return data_ + 4; }
|
||||
constexpr operator std::basic_string_view<char>() const { return "ConstConversionOp"; }
|
||||
};
|
||||
ConstConversionOperator cv;
|
||||
std::basic_string_view<char> sv = cv;
|
||||
assert(sv == "ConstConversionOp");
|
||||
}
|
||||
|
||||
struct DeletedConversionOperator {
|
||||
const char* data_ = "test";
|
||||
constexpr const char* begin() const { return data_; }
|
||||
constexpr const char* end() const { return data_ + 4; }
|
||||
operator std::basic_string_view<char>() = delete;
|
||||
};
|
||||
|
||||
struct DeletedConstConversionOperator {
|
||||
const char* data_ = "test";
|
||||
constexpr const char* begin() const { return data_; }
|
||||
constexpr const char* end() const { return data_ + 4; }
|
||||
operator std::basic_string_view<char>() const = delete;
|
||||
};
|
||||
|
||||
static_assert(std::is_constructible_v<std::string_view, DeletedConversionOperator>);
|
||||
static_assert(std::is_constructible_v<std::string_view, const DeletedConversionOperator>);
|
||||
static_assert(std::is_constructible_v<std::string_view, DeletedConstConversionOperator>);
|
||||
static_assert(std::is_constructible_v<std::string_view, const DeletedConstConversionOperator>);
|
||||
|
||||
// Test that we're not trying to use the type's conversion operator to string_view in the constructor.
|
||||
{
|
||||
const DeletedConversionOperator d;
|
||||
std::basic_string_view<char> csv = d;
|
||||
assert(csv == "test");
|
||||
}
|
||||
|
||||
{
|
||||
DeletedConstConversionOperator dc;
|
||||
std::basic_string_view<char> sv = dc;
|
||||
assert(sv == "test");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(std::is_constructible_v<std::string_view, std::vector<char>&>);
|
||||
static_assert(std::is_constructible_v<std::string_view, const std::vector<char>&>);
|
||||
static_assert(std::is_constructible_v<std::string_view, std::vector<char>&&>);
|
||||
static_assert(std::is_constructible_v<std::string_view, const std::vector<char>&&>);
|
||||
|
||||
using SizedButNotContiguousRange = std::ranges::subrange<random_access_iterator<char*>>;
|
||||
static_assert(!std::ranges::contiguous_range<SizedButNotContiguousRange>);
|
||||
static_assert(std::ranges::sized_range<SizedButNotContiguousRange>);
|
||||
static_assert(!std::is_constructible_v<std::string_view, SizedButNotContiguousRange>);
|
||||
|
||||
using ContiguousButNotSizedRange = std::ranges::subrange<contiguous_iterator<char*>, sentinel_wrapper<contiguous_iterator<char*>>, std::ranges::subrange_kind::unsized>;
|
||||
static_assert(std::ranges::contiguous_range<ContiguousButNotSizedRange>);
|
||||
static_assert(!std::ranges::sized_range<ContiguousButNotSizedRange>);
|
||||
static_assert(!std::is_constructible_v<std::string_view, ContiguousButNotSizedRange>);
|
||||
|
||||
static_assert(!std::is_constructible_v<std::string_view, std::vector<char16_t>>); // different CharT
|
||||
|
||||
struct WithStringViewConversionOperator {
|
||||
char* begin() const;
|
||||
char* end() const;
|
||||
operator std::string_view() const { return {}; }
|
||||
};
|
||||
|
||||
static_assert(std::is_constructible_v<std::string_view, WithStringViewConversionOperator>); // lvalue
|
||||
static_assert(std::is_constructible_v<std::string_view, const WithStringViewConversionOperator&>); // const lvalue
|
||||
static_assert(std::is_constructible_v<std::string_view, WithStringViewConversionOperator&&>); // rvalue
|
||||
|
||||
template <class CharTraits>
|
||||
struct WithTraitsType {
|
||||
typename CharTraits::char_type* begin() const;
|
||||
typename CharTraits::char_type* end() const;
|
||||
using traits_type = CharTraits;
|
||||
};
|
||||
|
||||
using CCT = constexpr_char_traits<char>;
|
||||
static_assert(std::is_constructible_v<std::string_view, WithTraitsType<std::char_traits<char>>>);
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
static_assert(std::is_constructible_v<std::wstring_view, WithTraitsType<std::char_traits<wchar_t>>>);
|
||||
#endif
|
||||
static_assert(std::is_constructible_v<std::basic_string_view<char, CCT>, WithTraitsType<CCT>>);
|
||||
static_assert(!std::is_constructible_v<std::string_view, WithTraitsType<CCT>>); // wrong traits type
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
static_assert(!std::is_constructible_v<std::wstring_view, WithTraitsType<std::char_traits<char>>>); // wrong traits type
|
||||
#endif
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
void test_throwing() {
|
||||
struct ThrowingData {
|
||||
char* begin() const { return nullptr; }
|
||||
char* end() const { return nullptr; }
|
||||
char* data() const { throw 42; return nullptr; }
|
||||
};
|
||||
try {
|
||||
ThrowingData x;
|
||||
(void) std::string_view(x);
|
||||
assert(false);
|
||||
} catch (int i) {
|
||||
assert(i == 42);
|
||||
}
|
||||
|
||||
struct ThrowingSize {
|
||||
char* begin() const { return nullptr; }
|
||||
char* end() const { return nullptr; }
|
||||
size_t size() const { throw 42; return 0; }
|
||||
};
|
||||
try {
|
||||
ThrowingSize x;
|
||||
(void) std::string_view(x);
|
||||
assert(false);
|
||||
} catch (int i) {
|
||||
assert(i == 42);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
static_assert(test());
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
test_throwing();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class Allocator>
|
||||
// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct dummy_char_traits : public std::char_traits<char> {};
|
||||
|
||||
template<typename CharT, typename Traits>
|
||||
void test ( const std::basic_string<CharT, Traits> &str ) {
|
||||
typedef std::basic_string_view<CharT, Traits> SV;
|
||||
ASSERT_NOEXCEPT(SV(str));
|
||||
|
||||
SV sv1 ( str );
|
||||
assert ( sv1.size() == str.size());
|
||||
assert ( sv1.data() == str.data());
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
|
||||
test ( std::string("QBCDE") );
|
||||
test ( std::string("") );
|
||||
test ( std::string() );
|
||||
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
test ( std::wstring(L"QBCDE") );
|
||||
test ( std::wstring(L"") );
|
||||
test ( std::wstring() );
|
||||
#endif
|
||||
|
||||
#if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
|
||||
test ( std::u8string{u8"QBCDE"} );
|
||||
test ( std::u8string{u8""} );
|
||||
test ( std::u8string{} );
|
||||
#endif
|
||||
|
||||
#if TEST_STD_VER >= 11
|
||||
test ( std::u16string{u"QBCDE"} );
|
||||
test ( std::u16string{u""} );
|
||||
test ( std::u16string{} );
|
||||
|
||||
test ( std::u32string{U"QBCDE"} );
|
||||
test ( std::u32string{U""} );
|
||||
test ( std::u32string{} );
|
||||
#endif
|
||||
|
||||
test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
|
||||
test ( std::basic_string<char, dummy_char_traits>("") );
|
||||
test ( std::basic_string<char, dummy_char_traits>() );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class Allocator>
|
||||
// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
struct dummy_char_traits : public std::char_traits<char> {};
|
||||
|
||||
int main(int, char**) {
|
||||
using string_view = std::basic_string_view<char>;
|
||||
using string = std:: basic_string <char, dummy_char_traits>;
|
||||
|
||||
{
|
||||
string s{"QBCDE"};
|
||||
string_view sv1 ( s );
|
||||
assert ( sv1.size() == s.size());
|
||||
assert ( sv1.data() == s.data());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
|
||||
|
||||
// <string_view>
|
||||
|
||||
// template<class Allocator>
|
||||
// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
struct dummy_char_traits : public std::char_traits<char> {};
|
||||
|
||||
int main(int, char**) {
|
||||
using string_view = std::basic_string_view<char, dummy_char_traits>;
|
||||
using string = std:: basic_string <char>;
|
||||
|
||||
{
|
||||
string s{"QBCDE"};
|
||||
string_view sv1 ( s );
|
||||
assert ( sv1.size() == s.size());
|
||||
assert ( sv1.data() == s.data());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
|
||||
// <string_view>
|
||||
|
||||
// Test that the constructors offered by std::basic_string_view are formulated
|
||||
// so they're compatible with implicit deduction guides.
|
||||
|
||||
#include <string_view>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "constexpr_char_traits.h"
|
||||
|
||||
// Overloads
|
||||
// ---------------
|
||||
// (1) basic_string_view() - NOT TESTED
|
||||
// (2) basic_string_view(const basic_string_view&)
|
||||
// (3) basic_string_view(const CharT*, size_type)
|
||||
// (4) basic_string_view(const CharT*)
|
||||
int main(int, char**)
|
||||
{
|
||||
{ // Testing (1)
|
||||
// Nothing to do. Cannot deduce without any arguments.
|
||||
}
|
||||
{ // Testing (2)
|
||||
const std::string_view sin("abc");
|
||||
std::basic_string_view s(sin);
|
||||
ASSERT_SAME_TYPE(decltype(s), std::string_view);
|
||||
assert(s == "abc");
|
||||
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
using WSV = std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>>;
|
||||
const WSV win(L"abcdef");
|
||||
std::basic_string_view w(win);
|
||||
ASSERT_SAME_TYPE(decltype(w), WSV);
|
||||
assert(w == L"abcdef");
|
||||
#endif
|
||||
}
|
||||
{ // Testing (3)
|
||||
std::basic_string_view s("abc", 2);
|
||||
ASSERT_SAME_TYPE(decltype(s), std::string_view);
|
||||
assert(s == "ab");
|
||||
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
std::basic_string_view w(L"abcdef", 4);
|
||||
ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
|
||||
assert(w == L"abcd");
|
||||
#endif
|
||||
}
|
||||
{ // Testing (4)
|
||||
std::basic_string_view s("abc");
|
||||
ASSERT_SAME_TYPE(decltype(s), std::string_view);
|
||||
assert(s == "abc");
|
||||
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
std::basic_string_view w(L"abcdef");
|
||||
ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
|
||||
assert(w == L"abcdef");
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
||||
|
||||
// <string_view>
|
||||
|
||||
// basic_string_view(nullptr_t) = delete; // C++2b
|
||||
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_convertible_v<decltype(nullptr), std::string_view>);
|
||||
static_assert(!std::is_constructible_v<std::string_view, decltype(nullptr)>);
|
||||
static_assert(!std::is_assignable_v<std::string_view, decltype(nullptr)>);
|
||||
Reference in New Issue
Block a user