[libcxx-commits] [libcxx] [libc++][sstream] P2495R3: Interfacing `stringstream`s with `string_view` (PR #80552)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Feb 18 03:38:52 PST 2024
================
@@ -0,0 +1,174 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
+// class basic_stringstream
+
+// template<class T>
+// basic_istringstream(const T& t, const Allocator& a);
+
+#include <cassert>
+#include <concepts>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+#include "constexpr_char_traits.h"
+#include "make_string.h"
+#include "nasty_string.h"
+#include "test_allocator.h"
+#include "test_convertible.h"
+#include "test_macros.h"
+
+#include "../../types.h"
+
+template <typename CharT>
+void test_sfinae() {
+ using SSTREAM = std::basic_istringstream<CharT, std::char_traits<CharT>, test_allocator<CharT>>;
+ using CSSTREAM = std::basic_istringstream<CharT, constexpr_char_traits<CharT>, test_allocator<CharT>>;
+
+ // `CharT*`
+ static_assert(std::constructible_from<SSTREAM, CharT*, const test_allocator<CharT>>);
+ static_assert(test_convertible<SSTREAM, CharT*, const test_allocator<CharT>>());
+
+ static_assert(std::constructible_from<CSSTREAM, CharT*, const test_allocator<CharT>>);
+ static_assert(test_convertible<CSSTREAM, CharT*, const test_allocator<CharT>>());
+
+ // `const CharT*`
+ static_assert(std::constructible_from<SSTREAM, const CharT*, const test_allocator<CharT>>);
+ static_assert(test_convertible<SSTREAM, const CharT*, const test_allocator<CharT>>());
+
+ static_assert(std::constructible_from<CSSTREAM, const CharT*, const test_allocator<CharT>>);
+ static_assert(test_convertible<CSSTREAM, const CharT*, const test_allocator<CharT>>());
+
+ // `std::basic_string_view<CharT>`
+ static_assert(std::constructible_from<SSTREAM, const std::basic_string_view<CharT>, const test_allocator<CharT>>);
+ static_assert(test_convertible<SSTREAM, std::basic_string_view<CharT>, const test_allocator<CharT>>());
+
+ static_assert(std::constructible_from<CSSTREAM,
+ const std::basic_string_view<CharT, constexpr_char_traits<CharT>>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<CSSTREAM,
+ std::basic_string_view<CharT, constexpr_char_traits<CharT>>,
+ const test_allocator<CharT>>());
+
+ // `std::basic_string<CharT>`
+ static_assert(std::constructible_from<SSTREAM, const std::basic_string<CharT>, const test_allocator<CharT>>);
+ static_assert(test_convertible<SSTREAM, const std::basic_string<CharT>, const test_allocator<CharT>>());
+
+ static_assert(std::constructible_from<CSSTREAM,
+ const std::basic_string<CharT, constexpr_char_traits<CharT>>,
+ const test_allocator<CharT>>);
+ static_assert(test_convertible<CSSTREAM,
+ const std::basic_string<CharT, constexpr_char_traits<CharT>>,
+ const test_allocator<CharT>>());
----------------
mordante wrote:
Can you test with a `std::basic_string` with a different allocator too?
https://github.com/llvm/llvm-project/pull/80552
More information about the libcxx-commits
mailing list