]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/to_chars/3.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / to_chars / 3.cc
1 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-string-conversions "" }
21
22 #include <charconv>
23 #include <string_view>
24 #include <testsuite_hooks.h>
25
26 template<typename C>
27 bool
28 check_to_chars(C val)
29 {
30 using std::string_view;
31
32 char buf1[32], buf2[32], buf3[32];
33 std::to_chars_result r1 = std::to_chars(buf1, buf1+sizeof(buf1), val);
34 if (r1.ec != std::errc{})
35 return false;
36 std::to_chars_result r2 = std::to_chars(buf2, buf2+sizeof(buf2), val, 10);
37 if (r2.ec != std::errc{})
38 return false;
39 if (string_view(buf1, r1.ptr - buf1) != string_view(buf2, r2.ptr - buf2))
40 return false;
41 std::to_chars_result r3 = std::to_chars(buf3, buf3+sizeof(buf3), (long)val);
42 if (string_view(buf1, r1.ptr - buf1) != string_view(buf3, r3.ptr - buf3))
43 return false;
44 return true;
45 }
46
47 void
48 test01()
49 {
50 VERIFY( check_to_chars(u'\x21') );
51 VERIFY( check_to_chars(U'\x21') );
52 #if _GLIBCXX_USE_WCHAR_T
53 VERIFY( check_to_chars(L'\x21') );
54 #endif
55 }
56
57 int main()
58 {
59 test01();
60 }