summaryrefslogtreecommitdiffstats
path: root/cxxformat.hpp
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2020-07-27 19:13:04 +0200
committerMarkus Mittendrein <git@maxmitti.tk>2020-07-27 19:13:04 +0200
commit00775aa16ffa28fcd822aa02ce5f99e626b7e874 (patch)
treeda93a40deb8276bd51ecbb2f44675fc56fbecae9 /cxxformat.hpp
parenta1d5cc867a8d89cecb3f2a82fe7688b2395749ab (diff)
downloadcxxformat-00775aa16ffa28fcd822aa02ce5f99e626b7e874.tar.gz
cxxformat-00775aa16ffa28fcd822aa02ce5f99e626b7e874.zip
Make auto conversion specifiers indepented of actual data, to allow constexpr determining
Diffstat (limited to 'cxxformat.hpp')
-rw-r--r--cxxformat.hpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/cxxformat.hpp b/cxxformat.hpp
index 064efbe..a5ff4ca 100644
--- a/cxxformat.hpp
+++ b/cxxformat.hpp
@@ -60,7 +60,7 @@ struct FormatConvert<const void *, Pointer, std::enable_if_t<std::is_pointer_v<P
template<typename From, typename Enable = void>
struct AutoConversion
{
- static bool conversion(const From &)
+ static bool conversion()
{
throw FormatException{""};
}
@@ -69,7 +69,7 @@ struct AutoConversion
template<char Conversion, typename From>
struct SimpleAutoConversion
{
- static constexpr char conversion(const From &)
+ static constexpr char conversion()
{
return Conversion;
}
@@ -202,13 +202,13 @@ namespace detail
using string_or_string_view = typename StringOrStringViewHelper<From>::type;
template<bool allowPointer = false, bool allowFallback = true, typename From>
- constexpr char autoConversionSpecifier(From &&from, std::size_t index = 0)
+ constexpr char autoConversionSpecifier(std::size_t index = 0)
{
try
{
if constexpr (!allowFallback)
{
- if constexpr(!std::is_same_v<char, decltype(AutoConversion<remove_cvref_t<From>>::conversion(std::forward<From>(from)))>)
+ if constexpr(!std::is_same_v<char, decltype(AutoConversion<remove_cvref_t<From>>::conversion())>)
{
if constexpr (std::is_pointer_v<From>)
{
@@ -224,7 +224,7 @@ namespace detail
}
}
}
- return AutoConversion<remove_cvref_t<From>>::conversion(std::forward<From>(from));
+ return AutoConversion<remove_cvref_t<From>>::conversion();
}
catch (const FormatException &)
{
@@ -334,11 +334,11 @@ namespace detail
std::string conversion{fmt[++i]};
if(conversion.front() == 'v')
{
- conversion = autoConversionSpecifier(std::forward<Arg>(arg), argumentIndex);
+ conversion = autoConversionSpecifier<false, true, Arg>(argumentIndex);
}
else if(conversion.front() == 'V')
{
- conversion = autoConversionSpecifier<true>(std::forward<Arg>(arg), argumentIndex);
+ conversion = autoConversionSpecifier<true, true, Arg>(argumentIndex);
}
auto continueFormatting = [directiveStart, &args..., fmt, &specification, &fieldWidth, &precision, i, conversion, argumentIndex](auto length, auto converted)
@@ -590,9 +590,9 @@ namespace detail
}
template<char conversion, size_t argumentIndex, typename Arg>
- constexpr char checkReplaceAutoConversion(Arg &&arg)
+ constexpr char checkReplaceAutoConversion()
{
- if constexpr (conversion == 'v' || conversion == 'V') return autoConversionSpecifier<conversion == 'V', false>(std::forward<Arg>(arg), argumentIndex);
+ if constexpr (conversion == 'v' || conversion == 'V') return autoConversionSpecifier<conversion == 'V', false, Arg>(argumentIndex);
else return conversion;
}
@@ -628,7 +628,7 @@ namespace detail
constexpr auto havePrecision = get<iAfterFieldWidth>(fmt) == '.';
constexpr size_t iAfterPrecision = [havePrecision, iAfterFieldWidth]() -> size_t { if constexpr (havePrecision) return getNumberEnd<fmt, iAfterFieldWidth + 1>(); else return iAfterFieldWidth; }();
- constexpr char conversion = checkReplaceAutoConversion<get<iAfterPrecision>(fmt), argumentIndex>(std::forward<Arg>(arg));
+ constexpr char conversion = checkReplaceAutoConversion<get<iAfterPrecision>(fmt), argumentIndex, Arg>();
if constexpr (conversion == 'c') return substr<0, i>(fmt).s + strprintf(makeDirective<fmt, conversion, i, iAfterPrecision, 0>().s, convert<char, false>(std::forward<Arg>(arg), "character", argumentIndex)) + format_s<substr<iAfterPrecision + 1>(fmt), 0, argumentIndex + 1>(std::forward<Args>(args)...);
else if constexpr (conversion == 'd' || conversion == 'i') return substr<0, i>(fmt).s + strprintf(makeDirective<fmt, conversion, i, iAfterPrecision, 'j'>().s, convert<std::intmax_t, false>(std::forward<Arg>(arg), "signed integer", argumentIndex)) + format_s<substr<iAfterPrecision + 1>(fmt), 0, argumentIndex + 1>(std::forward<Args>(args)...);