[libcxx-commits] [PATCH] D141263: [libc++][test] Silence MSVC warning

Casey Carter via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 9 15:04:34 PST 2023


CaseyCarter added inline comments.


================
Comment at: libcxx/test/std/ranges/range.factories/range.istream.view/utils.h:9
 auto make_string(const char (&in)[N]) {
-  std::basic_string<CharT> r(N - 1, static_cast<CharT>(0));
-  for (std::size_t i = 0; i < N - 1; ++i) {
-    r[i] = static_cast<CharT>(in[i]);
-  }
-  return r;
+  return std::basic_string<CharT>(in + 0, in + (N - 1));
 }
----------------
philnik wrote:
> Seems even simpler.
The (pointer, length) constructor would only work when `CharT` is `char`, this works for any `CharT` to which a `const char` lvalue converts. Most notably that includes `basic_string<wchar_t>` which the tests use.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141263/new/

https://reviews.llvm.org/D141263



More information about the libcxx-commits mailing list