typedef typename _Char_types<_CharT>::off_type off_type;
typedef typename _Char_types<_CharT>::state_type state_type;
- static void
+ static _GLIBCXX14_CONSTEXPR void
assign(char_type& __c1, const char_type& __c2)
{ __c1 = __c2; }
lt(const char_type& __c1, const char_type& __c2)
{ return __c1 < __c2; }
- static int
+ static _GLIBCXX14_CONSTEXPR int
compare(const char_type* __s1, const char_type* __s2, std::size_t __n);
- static std::size_t
+ static _GLIBCXX14_CONSTEXPR std::size_t
length(const char_type* __s);
- static const char_type*
+ static _GLIBCXX14_CONSTEXPR const char_type*
find(const char_type* __s, std::size_t __n, const char_type& __a);
static char_type*
{ return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
};
+// #define __cpp_lib_constexpr_char_traits 201611
+
template<typename _CharT>
- int
+ _GLIBCXX14_CONSTEXPR int
char_traits<_CharT>::
compare(const char_type* __s1, const char_type* __s2, std::size_t __n)
{
}
template<typename _CharT>
- std::size_t
+ _GLIBCXX14_CONSTEXPR std::size_t
char_traits<_CharT>::
length(const char_type* __p)
{
}
template<typename _CharT>
- const typename char_traits<_CharT>::char_type*
+ _GLIBCXX14_CONSTEXPR const typename char_traits<_CharT>::char_type*
char_traits<_CharT>::
find(const char_type* __s, std::size_t __n, const char_type& __a)
{
typedef streamoff off_type;
typedef mbstate_t state_type;
- static void
+ static _GLIBCXX17_CONSTEXPR void
assign(char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
{ __c1 = __c2; }
< static_cast<unsigned char>(__c2));
}
- static int
+ static /* _GLIBCXX17_CONSTEXPR */ int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
if (__n == 0)
return __builtin_memcmp(__s1, __s2, __n);
}
- static size_t
+ static /* _GLIBCXX17_CONSTEXPR */ size_t
length(const char_type* __s)
{ return __builtin_strlen(__s); }
- static const char_type*
+ static /* _GLIBCXX17_CONSTEXPR */ const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{
if (__n == 0)
typedef wstreampos pos_type;
typedef mbstate_t state_type;
- static void
+ static _GLIBCXX17_CONSTEXPR void
assign(char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
{ __c1 = __c2; }
lt(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
{ return __c1 < __c2; }
- static int
+ static /* _GLIBCXX17_CONSTEXPR */ int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
if (__n == 0)
return wmemcmp(__s1, __s2, __n);
}
- static size_t
+ static /* _GLIBCXX17_CONSTEXPR */ size_t
length(const char_type* __s)
{ return wcslen(__s); }
- static const char_type*
+ static /* _GLIBCXX17_CONSTEXPR */ const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{
if (__n == 0)
typedef u16streampos pos_type;
typedef mbstate_t state_type;
- static void
+ static _GLIBCXX17_CONSTEXPR void
assign(char_type& __c1, const char_type& __c2) noexcept
{ __c1 = __c2; }
lt(const char_type& __c1, const char_type& __c2) noexcept
{ return __c1 < __c2; }
- static int
+ static _GLIBCXX17_CONSTEXPR int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
for (size_t __i = 0; __i < __n; ++__i)
return 0;
}
- static size_t
+ static _GLIBCXX17_CONSTEXPR size_t
length(const char_type* __s)
{
size_t __i = 0;
return __i;
}
- static const char_type*
+ static _GLIBCXX17_CONSTEXPR const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{
for (size_t __i = 0; __i < __n; ++__i)
typedef u32streampos pos_type;
typedef mbstate_t state_type;
- static void
+ static _GLIBCXX17_CONSTEXPR void
assign(char_type& __c1, const char_type& __c2) noexcept
{ __c1 = __c2; }
lt(const char_type& __c1, const char_type& __c2) noexcept
{ return __c1 < __c2; }
- static int
+ static _GLIBCXX17_CONSTEXPR int
compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
for (size_t __i = 0; __i < __n; ++__i)
return 0;
}
- static size_t
+ static _GLIBCXX17_CONSTEXPR size_t
length(const char_type* __s)
{
size_t __i = 0;
return __i;
}
- static const char_type*
+ static _GLIBCXX17_CONSTEXPR const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{
for (size_t __i = 0; __i < __n; ++__i)
--- /dev/null
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++1z } }
+
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string>
+
+template<typename CT>
+ constexpr bool
+ test_assign()
+ {
+ using char_type = typename CT::char_type;
+ char_type s1[2] = {};
+ const char_type s2[2] = {1, 0};
+ CT::assign(s1[0], s2[0]);
+ return s1[0] == char_type{1};
+ }
+
+template<typename CT>
+ constexpr bool
+ test_compare()
+ {
+ using char_type = typename CT::char_type;
+ const char_type s1[3] = {1, 2, 3};
+ const char_type s2[3] = {1, 2, 3};
+ if (CT::compare(s1, s2, 3) != 0)
+ return false;
+ if (CT::compare(s2, s1, 3) != 0)
+ return false;
+ if (CT::compare(s1+1, s2, 2) <= 0)
+ return false;
+ return true;
+ }
+
+template<typename CT>
+ constexpr bool
+ test_length()
+ {
+ using char_type = typename CT::char_type;
+ const char_type s1[4] = {1, 2, 3, 0};
+ if (CT::length(s1) != 3)
+ return false;
+ if (CT::length(s1+1) != 2)
+ return false;
+ return true;
+ }
+
+template<typename CT>
+ constexpr bool
+ test_find()
+ {
+ using char_type = typename CT::char_type;
+ const char_type s1[3] = {1, 2, 3};
+ if (CT::find(s1, 3, char_type{2}) != s1+1)
+ return false;
+ if (CT::find(s1, 3, char_type{4}) != nullptr)
+ return false;
+ return true;
+ }
+
+#ifndef __cpp_lib_constexpr_char_traits
+// #error Feature-test macro for constexpr char_traits is missing
+#elif __cpp_lib_constexpr_char_traits != 201611
+// #error Feature-test macro for constexpr char_traits has the wrong value
+#endif
+
+static_assert( test_assign<std::char_traits<char>>() );
+// static_assert( test_compare<std::char_traits<char>>() );
+// static_assert( test_length<std::char_traits<char>>() );
+// static_assert( test_find<std::char_traits<char>>() );
+#ifdef _GLIBCXX_USE_WCHAR_T
+static_assert( test_assign<std::char_traits<wchar_t>>() );
+// static_assert( test_compare<std::char_traits<wchar_t>>() );
+// static_assert( test_length<std::char_traits<wchar_t>>() );
+// static_assert( test_find<std::char_traits<wchar_t>>() );
+#endif
+static_assert( test_assign<std::char_traits<char16_t>>() );
+static_assert( test_compare<std::char_traits<char16_t>>() );
+static_assert( test_length<std::char_traits<char16_t>>() );
+static_assert( test_find<std::char_traits<char16_t>>() );
+static_assert( test_assign<std::char_traits<char32_t>>() );
+static_assert( test_compare<std::char_traits<char32_t>>() );
+static_assert( test_length<std::char_traits<char32_t>>() );
+static_assert( test_find<std::char_traits<char32_t>>() );
+
+struct C { unsigned char c; };
+constexpr bool operator==(const C& c1, const C& c2) { return c1.c == c2.c; }
+constexpr bool operator<(const C& c1, const C& c2) { return c1.c < c2.c; }
+static_assert( test_assign<std::char_traits<C>>() );
+static_assert( test_compare<std::char_traits<C>>() );
+static_assert( test_length<std::char_traits<C>>() );
+static_assert( test_find<std::char_traits<C>>() );