View source code Display the source code in std/conv.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.conv.octal - multiple declarations

Function octal

The octal facility provides a means to declare a number in base 8. Using octal!177 or octal!"177" for 127 represented in octal (same as 0177 in C).

The rules for strings are the usual for literals: If it can fit in an int, it is an int. Otherwise, it is a long. But, if the user specifically asks for a long with the L suffix, always give the long. Give an unsigned iff it is asked for with the U or u suffix. Octals created from integers preserve the type of the passed-in integral.

Prototypes

int octal(string num)() @property
if (octalFitsInInt!num && !literalIsLong!num && !literalIsUnsigned!num);

long octal(string num)() @property
if ((!octalFitsInInt!num || literalIsLong!num) && !literalIsUnsigned!num);

uint octal(string num)() @property
if (octalFitsInInt!num && !literalIsLong!num && literalIsUnsigned!num);

ulong octal(string num)() @property
if ((!octalFitsInInt!num || literalIsLong!num) && literalIsUnsigned!num);

See Also

parse for parsing octal strings at runtime.

Example

// same as 0177
auto x = octal!177;
// octal is a compile-time device
enum y = octal!160;
// Create an unsigned octal
auto z = octal!"1_000_000u";

Example

int a = octal!(int, "10");

assert(a == 8);

Enum member octal

The octal facility provides a means to declare a number in base 8. Using octal!177 or octal!"177" for 127 represented in octal (same as 0177 in C).

The rules for strings are the usual for literals: If it can fit in an int, it is an int. Otherwise, it is a long. But, if the user specifically asks for a long with the L suffix, always give the long. Give an unsigned iff it is asked for with the U or u suffix. Octals created from integers preserve the type of the passed-in integral.

Declaration

enum octal(alias s) = octal!(typeof(s), to!string(s));

See Also

parse for parsing octal strings at runtime.

Example

// same as 0177
auto x = octal!177;
// octal is a compile-time device
enum y = octal!160;
// Create an unsigned octal
auto z = octal!"1_000_000u";

Example

int a = octal!(int, "10");

assert(a == 8);

Authors

Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara

License

Boost License 1.0.

Comments