[libcxx-commits] [PATCH] D156022: [NFC][libc++][format] Switches to from_range constructor.
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jul 22 04:20:03 PDT 2023
Mordante created this revision.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Some places in the format library were identified to benefit from
basic_string's from_range constructor. At that time that constructor was
not implemented. It's implemented now so adjust the code to use this new
constructor.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156022
Files:
libcxx/include/__format/range_default_formatter.h
libcxx/include/__format/range_formatter.h
Index: libcxx/include/__format/range_formatter.h
===================================================================
--- libcxx/include/__format/range_formatter.h
+++ libcxx/include/__format/range_formatter.h
@@ -28,6 +28,7 @@
#include <__iterator/back_insert_iterator.h>
#include <__ranges/concepts.h>
#include <__ranges/data.h>
+#include <__ranges/from_range.h>
#include <__ranges/size.h>
#include <__type_traits/remove_cvref.h>
#include <string_view>
@@ -184,13 +185,7 @@
std::formatter<basic_string<_CharT>, _CharT> __formatter;
if (__debug_format)
__formatter.set_debug_format();
- // P2106's from_range has not been implemented yet. Instead use a simple
- // copy operation.
- // TODO FMT use basic_string's "from_range" constructor.
- // return std::formatter<basic_string<_CharT>, _CharT>{}.format(basic_string<_CharT>{from_range, __range}, __ctx);
- basic_string<_CharT> __str;
- ranges::copy(__range, back_insert_iterator{__str});
- return __formatter.format(__str, __ctx);
+ return __formatter.format(basic_string<_CharT>{from_range, __range}, __ctx);
}
}
Index: libcxx/include/__format/range_default_formatter.h
===================================================================
--- libcxx/include/__format/range_default_formatter.h
+++ libcxx/include/__format/range_default_formatter.h
@@ -24,6 +24,7 @@
#include <__iterator/back_insert_iterator.h>
#include <__ranges/concepts.h>
#include <__ranges/data.h>
+#include <__ranges/from_range.h>
#include <__ranges/size.h>
#include <__type_traits/conditional.h>
#include <__type_traits/remove_cvref.h>
@@ -196,15 +197,8 @@
// specialization is the "basic" string formatter in libc++.
if constexpr (ranges::contiguous_range<_Rp> && std::ranges::sized_range<_Rp>)
return __underlying_.format(basic_string_view<_CharT>{ranges::data(__range), ranges::size(__range)}, __ctx);
- else {
- // P2106's from_range has not been implemented yet. Instead use a simple
- // copy operation.
- // TODO FMT use basic_string's "from_range" constructor.
- // return __underlying_.format(basic_string<_CharT>{from_range, __range}, __ctx);
- basic_string<_CharT> __str;
- std::ranges::copy(__range, back_insert_iterator{__str});
- return __underlying_.format(static_cast<basic_string_view<_CharT>>(__str), __ctx);
- }
+ else
+ return __underlying_.format(basic_string<_CharT>{from_range, __range}, __ctx);
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156022.543168.patch
Type: text/x-patch
Size: 2506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230722/053df218/attachment.bin>
More information about the libcxx-commits
mailing list