Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
| 12 | // template<> struct char_traits<char> |
| 13 | |
| 14 | // static const char_type* find(const char_type* s, size_t n, const char_type& a); |
Marshall Clow | ce921fa | 2017-01-12 04:37:14 +0000 | [diff] [blame^] | 15 | // constexpr in C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 16 | |
| 17 | #include <string> |
| 18 | #include <cassert> |
| 19 | |
Marshall Clow | ce921fa | 2017-01-12 04:37:14 +0000 | [diff] [blame^] | 20 | #include "test_macros.h" |
| 21 | |
| 22 | #if TEST_STD_VER > 14 |
| 23 | constexpr bool test_constexpr() |
| 24 | { |
| 25 | constexpr const char *p = "123"; |
| 26 | return std::char_traits<char>::find(p, 3, '1') == p |
| 27 | && std::char_traits<char>::find(p, 3, '2') == p + 1 |
| 28 | && std::char_traits<char>::find(p, 3, '3') == p + 2 |
| 29 | && std::char_traits<char>::find(p, 3, '4') == nullptr; |
| 30 | } |
| 31 | #endif |
| 32 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | int main() |
| 34 | { |
| 35 | char s1[] = {1, 2, 3}; |
| 36 | assert(std::char_traits<char>::find(s1, 3, char(1)) == s1); |
| 37 | assert(std::char_traits<char>::find(s1, 3, char(2)) == s1+1); |
| 38 | assert(std::char_traits<char>::find(s1, 3, char(3)) == s1+2); |
| 39 | assert(std::char_traits<char>::find(s1, 3, char(4)) == 0); |
| 40 | assert(std::char_traits<char>::find(s1, 3, char(0)) == 0); |
Marshall Clow | 6bcbced | 2015-02-13 16:04:42 +0000 | [diff] [blame] | 41 | assert(std::char_traits<char>::find(NULL, 0, char(0)) == 0); |
Marshall Clow | ce921fa | 2017-01-12 04:37:14 +0000 | [diff] [blame^] | 42 | |
| 43 | #if TEST_STD_VER > 14 |
| 44 | static_assert(test_constexpr(), "" ); |
| 45 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 46 | } |