dlang-book/book/05-данные-и-функции-функциональный-стиль/src/chapter-5-5-1/app.d

27 lines
678 B
D
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import std.stdio;
void transmogrify(uint value)
{
writeln("Вызов функции с uint: ", value);
}
void transmogrify(long value)
{
writeln("Вызов функции с long: ", value);
}
void transmogrify(T)(T value)
{
writeln("Вызов функции с T: ", value);
}
unittest
{
transmogrify(42); // Вы­зы­ва­ет transmogrify(uint)
transmogrify("hello"); // Вы­зы­ва­ет transmogrify(T), T=string
transmogrify(1.1); // Вы­зы­ва­ет transmogrify(T), T=double
// Вызов функции с uint: 42
// Вызов функции с T: hello
// Вызов функции с T: 1.1
}