//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // test: // template // basic_string // to_string(charT zero = charT('0'), charT one = charT('1')) const; // // template // basic_string > to_string() const; // // template // basic_string, allocator > to_string() const; // // basic_string, allocator > to_string() const; #include #include #include #include #include "test_macros.h" #if defined(TEST_COMPILER_CLANG) #pragma clang diagnostic ignored "-Wtautological-compare" #elif defined(TEST_COMPILER_C1XX) #pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed. #endif template std::bitset make_bitset() { std::bitset v; for (std::size_t i = 0; i < N; ++i) v[i] = static_cast(std::rand() & 1); return v; } template void test_to_string() { { std::bitset v = make_bitset(); { std::wstring s = v.template to_string, std::allocator >(); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::wstring s = v.template to_string >(); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::string s = v.template to_string(); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::string s = v.to_string(); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } } { std::bitset v = make_bitset(); { std::wstring s = v.template to_string, std::allocator >('0'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::wstring s = v.template to_string >('0'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::string s = v.template to_string('0'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::string s = v.to_string('0'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } } { std::bitset v = make_bitset(); { std::wstring s = v.template to_string, std::allocator >('0', '1'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::wstring s = v.template to_string >('0', '1'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::string s = v.template to_string('0', '1'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } { std::string s = v.to_string('0', '1'); for (std::size_t i = 0; i < N; ++i) if (v[i]) assert(s[N - 1 - i] == '1'); else assert(s[N - 1 - i] == '0'); } } } int main(int, char**) { test_to_string<0>(); test_to_string<1>(); test_to_string<31>(); test_to_string<32>(); test_to_string<33>(); test_to_string<63>(); test_to_string<64>(); test_to_string<65>(); test_to_string<1000>(); return 0; }