libcxx initial import
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static void assign(char_type& c1, const char_type& c2);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c = '\0';
|
||||
std::char_traits<char>::assign(c, 'a');
|
||||
assert(c == 'a');
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static char_type* assign(char_type* s, size_t n, char_type a);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
char s1[] = {1, 2, 3};
|
||||
char s2[3] = {0};
|
||||
assert(std::char_traits<char>::assign(s2, 3, char(5)) == s2);
|
||||
assert(s2[0] == char(5));
|
||||
assert(s2[1] == char(5));
|
||||
assert(s2[2] == char(5));
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static int compare(const char_type* s1, const char_type* s2, size_t n);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(std::char_traits<char>::compare("", "", 0) == 0);
|
||||
|
||||
assert(std::char_traits<char>::compare("1", "1", 1) == 0);
|
||||
assert(std::char_traits<char>::compare("1", "2", 1) < 0);
|
||||
assert(std::char_traits<char>::compare("2", "1", 1) > 0);
|
||||
|
||||
assert(std::char_traits<char>::compare("12", "12", 2) == 0);
|
||||
assert(std::char_traits<char>::compare("12", "13", 2) < 0);
|
||||
assert(std::char_traits<char>::compare("12", "22", 2) < 0);
|
||||
assert(std::char_traits<char>::compare("13", "12", 2) > 0);
|
||||
assert(std::char_traits<char>::compare("22", "12", 2) > 0);
|
||||
|
||||
assert(std::char_traits<char>::compare("123", "123", 3) == 0);
|
||||
assert(std::char_traits<char>::compare("123", "223", 3) < 0);
|
||||
assert(std::char_traits<char>::compare("123", "133", 3) < 0);
|
||||
assert(std::char_traits<char>::compare("123", "124", 3) < 0);
|
||||
assert(std::char_traits<char>::compare("223", "123", 3) > 0);
|
||||
assert(std::char_traits<char>::compare("133", "123", 3) > 0);
|
||||
assert(std::char_traits<char>::compare("124", "123", 3) > 0);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static char_type* copy(char_type* s1, const char_type* s2, size_t n);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
char s1[] = {1, 2, 3};
|
||||
char s2[3] = {0};
|
||||
assert(std::char_traits<char>::copy(s2, s1, 3) == s2);
|
||||
assert(s2[0] == char(1));
|
||||
assert(s2[1] == char(2));
|
||||
assert(s2[2] == char(3));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static constexpr int_type eof();
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(std::char_traits<char>::eof() == EOF);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static constexpr bool eq(char_type c1, char_type c2);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c = '\0';
|
||||
assert(std::char_traits<char>::eq('a', 'a'));
|
||||
assert(!std::char_traits<char>::eq('a', 'A'));
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static constexpr bool eq_int_type(int_type c1, int_type c2);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert( std::char_traits<char>::eq_int_type('a', 'a'));
|
||||
assert(!std::char_traits<char>::eq_int_type('a', 'A'));
|
||||
assert(!std::char_traits<char>::eq_int_type(std::char_traits<char>::eof(), 'A'));
|
||||
assert( std::char_traits<char>::eq_int_type(std::char_traits<char>::eof(),
|
||||
std::char_traits<char>::eof()));
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static const char_type* find(const char_type* s, size_t n, const char_type& a);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
char s1[] = {1, 2, 3};
|
||||
assert(std::char_traits<char>::find(s1, 3, char(1)) == s1);
|
||||
assert(std::char_traits<char>::find(s1, 3, char(2)) == s1+1);
|
||||
assert(std::char_traits<char>::find(s1, 3, char(3)) == s1+2);
|
||||
assert(std::char_traits<char>::find(s1, 3, char(4)) == 0);
|
||||
assert(std::char_traits<char>::find(s1, 3, char(0)) == 0);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static size_t length(const char_type* s);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(std::char_traits<char>::length("") == 0);
|
||||
assert(std::char_traits<char>::length("a") == 1);
|
||||
assert(std::char_traits<char>::length("aa") == 2);
|
||||
assert(std::char_traits<char>::length("aaa") == 3);
|
||||
assert(std::char_traits<char>::length("aaaa") == 4);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static constexpr bool lt(char_type c1, char_type c2);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
char c = '\0';
|
||||
assert(!std::char_traits<char>::lt('a', 'a'));
|
||||
assert( std::char_traits<char>::lt('A', 'a'));
|
||||
assert(!std::char_traits<char>::lt('A' + 127, 'a'));
|
||||
assert(!std::char_traits<char>::lt('A' - 127, 'a'));
|
||||
assert( std::char_traits<char>::lt('A', 'a' + 127));
|
||||
assert( std::char_traits<char>::lt('A', 'a' - 127));
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static char_type* move(char_type* s1, const char_type* s2, size_t n);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
char s1[] = {1, 2, 3};
|
||||
assert(std::char_traits<char>::move(s1, s1+1, 2) == s1);
|
||||
assert(s1[0] == char(2));
|
||||
assert(s1[1] == char(3));
|
||||
assert(s1[2] == char(3));
|
||||
s1[2] = char(0);
|
||||
assert(std::char_traits<char>::move(s1+1, s1, 2) == s1+1);
|
||||
assert(s1[0] == char(2));
|
||||
assert(s1[1] == char(2));
|
||||
assert(s1[2] == char(3));
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static constexpr int_type not_eof(int_type c);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(std::char_traits<char>::not_eof('a') == 'a');
|
||||
assert(std::char_traits<char>::not_eof('A') == 'A');
|
||||
assert(std::char_traits<char>::not_eof(0) == 0);
|
||||
assert(std::char_traits<char>::not_eof(std::char_traits<char>::eof()) !=
|
||||
std::char_traits<char>::eof());
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static constexpr char_type to_char_type(int_type c);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(std::char_traits<char>::to_char_type('a') == 'a');
|
||||
assert(std::char_traits<char>::to_char_type('A') == 'A');
|
||||
assert(std::char_traits<char>::to_char_type(0) == 0);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// static constexpr int_type to_int_type(char_type c);
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(std::char_traits<char>::to_int_type('a') == 'a');
|
||||
assert(std::char_traits<char>::to_int_type('A') == 'A');
|
||||
assert(std::char_traits<char>::to_int_type(0) == 0);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <string>
|
||||
|
||||
// template<> struct char_traits<char>
|
||||
|
||||
// typedef char char_type;
|
||||
// typedef int int_type;
|
||||
// typedef streamoff off_type;
|
||||
// typedef streampos pos_type;
|
||||
// typedef mbstate_t state_type;
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::char_traits<char>::char_type, char>::value), "");
|
||||
static_assert((std::is_same<std::char_traits<char>::int_type, int>::value), "");
|
||||
static_assert((std::is_same<std::char_traits<char>::off_type, std::streamoff>::value), "");
|
||||
static_assert((std::is_same<std::char_traits<char>::pos_type, std::streampos>::value), "");
|
||||
static_assert((std::is_same<std::char_traits<char>::state_type, std::mbstate_t>::value), "");
|
||||
}
|
||||
Reference in New Issue
Block a user