Add tests to make sure that <string_view> provides std::size/data/empty in C++17 mode. This is LWG#3009, coming up for a vote in JAX - but we already do it, just don't have tests
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323719 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -23,6 +23,10 @@
|
|||||||
|
|
||||||
#include "test_macros.h"
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
#include <string_view>
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
void test_const_container( const C& c )
|
void test_const_container( const C& c )
|
||||||
{
|
{
|
||||||
@@ -72,6 +76,12 @@ int main()
|
|||||||
test_const_container ( a );
|
test_const_container ( a );
|
||||||
test_const_container ( il );
|
test_const_container ( il );
|
||||||
|
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
std::string_view sv{"ABC"};
|
||||||
|
test_container ( sv );
|
||||||
|
test_const_container ( sv );
|
||||||
|
#endif
|
||||||
|
|
||||||
static constexpr int arrA [] { 1, 2, 3 };
|
static constexpr int arrA [] { 1, 2, 3 };
|
||||||
test_const_array ( arrA );
|
test_const_array ( arrA );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
|
|
||||||
#include "test_macros.h"
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
#include <string_view>
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
void test_const_container( const C& c )
|
void test_const_container( const C& c )
|
||||||
{
|
{
|
||||||
@@ -74,6 +78,12 @@ int main()
|
|||||||
test_const_container ( a );
|
test_const_container ( a );
|
||||||
test_const_container ( il );
|
test_const_container ( il );
|
||||||
|
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
std::string_view sv{"ABC"};
|
||||||
|
test_container ( sv );
|
||||||
|
test_const_container ( sv );
|
||||||
|
#endif
|
||||||
|
|
||||||
static constexpr int arrA [] { 1, 2, 3 };
|
static constexpr int arrA [] { 1, 2, 3 };
|
||||||
test_const_array ( arrA );
|
test_const_array ( arrA );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
|
|
||||||
#include "test_macros.h"
|
#include "test_macros.h"
|
||||||
|
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
#include <string_view>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
void test_const_container( const C& c )
|
void test_const_container( const C& c )
|
||||||
{
|
{
|
||||||
@@ -65,7 +70,6 @@ int main()
|
|||||||
std::list<int> l; l.push_back(2);
|
std::list<int> l; l.push_back(2);
|
||||||
std::array<int, 1> a; a[0] = 3;
|
std::array<int, 1> a; a[0] = 3;
|
||||||
std::initializer_list<int> il = { 4 };
|
std::initializer_list<int> il = { 4 };
|
||||||
|
|
||||||
test_container ( v );
|
test_container ( v );
|
||||||
test_container ( l );
|
test_container ( l );
|
||||||
test_container ( a );
|
test_container ( a );
|
||||||
@@ -76,6 +80,12 @@ int main()
|
|||||||
test_const_container ( a );
|
test_const_container ( a );
|
||||||
test_const_container ( il );
|
test_const_container ( il );
|
||||||
|
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
std::string_view sv{"ABC"};
|
||||||
|
test_container ( sv );
|
||||||
|
test_const_container ( sv );
|
||||||
|
#endif
|
||||||
|
|
||||||
static constexpr int arrA [] { 1, 2, 3 };
|
static constexpr int arrA [] { 1, 2, 3 };
|
||||||
test_const_array ( arrA );
|
test_const_array ( arrA );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ void test ( const CharT *s, size_t len ) {
|
|||||||
std::basic_string_view<CharT> sv ( s, len );
|
std::basic_string_view<CharT> sv ( s, len );
|
||||||
assert ( sv.length() == len );
|
assert ( sv.length() == len );
|
||||||
assert ( sv.data() == s );
|
assert ( sv.data() == s );
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
// make sure we pick up std::data, too!
|
||||||
|
assert ( sv.data() == std::data(sv));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ void test2 ( const CharT *s, size_t len ) {
|
|||||||
assert ( sv1.empty() == (len == 0));
|
assert ( sv1.empty() == (len == 0));
|
||||||
assert ( sv1.size() == sv1.length());
|
assert ( sv1.size() == sv1.length());
|
||||||
assert ( sv1.max_size() > sv1.size());
|
assert ( sv1.max_size() > sv1.size());
|
||||||
|
#if TEST_STD_VER > 14
|
||||||
|
// make sure we pick up std::size, too!
|
||||||
|
assert ( sv1.size() == std::size(sv1));
|
||||||
|
assert ( sv1.empty() == std::empty(sv1));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user