View source code
Display the source code in std/typecons.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

std.typecons.Tuple.toString.toString - multiple declarations

Function Tuple.toString.toString

Converts to string.

string toString() const;

Returns

The string representation of this Tuple.

Function Tuple.toString.toString

Formats Tuple with either %s, %(inner%) or %(inner%|sep%).

void toString(DG) (
  scope DG sink
) const;

void toString(DG, Char) (
  scope DG sink,
  const ref FormatSpec!Char fmt
) const;

Formats supported by Tuple
FormatDescription

%s

Format like Tuple!(types)(elements formatted with %s each).

%(inner%)

The format inner is applied the expanded Tuple

so it may contain as many formats as the Tuple has fields.

%(inner%|sep%)

The format inner is one format

that is applied on all fields of the Tuple. The inner format must be compatible to all of them.

Tuple!(int, double)[3] tupList = [ tuple(1, 1.0), tuple(2, 4.0), tuple(3, 9.0) ];

// Default format
assert(format("%s", tuple("a", 1)) == `Tuple!(string, int)("a", 1)`);

// One Format for each individual component
assert(format("%(%#x v %.4f w %#x%)", tuple(1, 1.0, 10))         == `0x1 v 1.0000 w 0xa`);
assert(format(  "%#x v %.4f w %#x"  , tuple(1, 1.0, 10).expand)  == `0x1 v 1.0000 w 0xa`);

// One Format for all components
assert(format("%(>%s<%| & %)", tuple("abc", 1, 2.3, [4, 5])) == `>abc< & >1< & >2.3< & >[4, 5]<`);

// Array of Tuples
assert(format("%(%(f(%d) = %.1f%);  %)", tupList) == `f(1) = 1.0;  f(2) = 4.0;  f(3) = 9.0`);


// Error: %( %) missing.
assertThrown!FormatException(
    format("%d, %f", tuple(1, 2.0)) == `1, 2.0`
);

// Error: %( %| %) missing.
assertThrown!FormatException(
    format("%d", tuple(1, 2)) == `1, 2`
);

// Error: %d inadequate for double.
assertThrown!FormatException(
    format("%(%d%|, %)", tuple(1, 2.0)) == `1, 2.0`
);

Authors

Andrei Alexandrescu, Bartosz Milewski, Don Clugston, Shin Fujishiro, Kenji Hara

License

Boost License 1.0.