[libcxx-commits] [libcxx] 7b580d8 - [NFC][libc++][format] Switches to from_range constructor.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 2 09:01:57 PDT 2023
Author: Mark de Wever
Date: 2023-08-02T18:01:48+02:00
New Revision: 7b580d8b40bddcf12b2cb2a5fed1a15205f02a9a
URL: https://github.com/llvm/llvm-project/commit/7b580d8b40bddcf12b2cb2a5fed1a15205f02a9a
DIFF: https://github.com/llvm/llvm-project/commit/7b580d8b40bddcf12b2cb2a5fed1a15205f02a9a.diff
LOG: [NFC][libc++][format] Switches to from_range constructor.
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.
Reviewed By: #libc, var-const
Differential Revision: https://reviews.llvm.org/D156022
Added:
Modified:
libcxx/include/__format/range_default_formatter.h
libcxx/include/__format/range_formatter.h
Removed:
################################################################################
diff --git a/libcxx/include/__format/range_default_formatter.h b/libcxx/include/__format/range_default_formatter.h
index bcab5d6afdd3f8..b35223ae933291 100644
--- a/libcxx/include/__format/range_default_formatter.h
+++ b/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>
@@ -197,15 +198,8 @@ struct _LIBCPP_TEMPLATE_VIS __range_default_formatter<_Kp, _Rp, _CharT> {
// 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);
}
};
diff --git a/libcxx/include/__format/range_formatter.h b/libcxx/include/__format/range_formatter.h
index 27870972c9d5fc..d13278009fcf89 100644
--- a/libcxx/include/__format/range_formatter.h
+++ b/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 @@ struct _LIBCPP_TEMPLATE_VIS range_formatter {
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);
}
}
More information about the libcxx-commits
mailing list