aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/conv.d
diff options
context:
space:
mode:
Diffstat (limited to 'libphobos/src/std/conv.d')
-rw-r--r--libphobos/src/std/conv.d15
1 files changed, 14 insertions, 1 deletions
diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d
index 9164e07..0f66065 100644
--- a/libphobos/src/std/conv.d
+++ b/libphobos/src/std/conv.d
@@ -4894,7 +4894,7 @@ if (isOctalLiteral(num))
template octal(alias decimalInteger)
if (is(typeof(decimalInteger)) && isIntegral!(typeof(decimalInteger)))
{
- enum octal = octal!(typeof(decimalInteger))(to!string(decimalInteger));
+ enum octal = convertToOctal(decimalInteger);
}
///
@@ -4910,6 +4910,19 @@ if (is(typeof(decimalInteger)) && isIntegral!(typeof(decimalInteger)))
auto d = octal!"0001_200_000";
}
+/*************************************
+ * Convert a decimal integer to an octal integer with the same digits.
+ * Params:
+ * i = integer to convert
+ * Returns:
+ * octal integer with the same type and same digits
+ */
+private T convertToOctal(T)(T i)
+{
+ assert((i % 10) < 8);
+ return i ? convertToOctal(i / 10) * 8 + i % 10 : 0;
+}
+
/*
Takes a string, num, which is an octal literal, and returns its
value, in the type T specified.