//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // 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 #pragma clang diagnostic ignored "-Wtautological-compare" 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() { 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>(); }