Перенос страниц

This commit is contained in:
Alexander Zhirov 2023-03-05 15:30:34 +03:00
parent 4d57446057
commit 4c954c9186
129 changed files with 14 additions and 15 deletions

View file

@ -0,0 +1,34 @@
import std.stdio;
T[] find(alias pred, T)(T[] input)
if (is(typeof(pred(input[0])) == bool))
{
for (; input.length > 0; input = input[1 .. $])
{
if (pred(input[0])) break;
}
return input;
}
unittest
{
int zero = 0;
bool isTypeLow(int x)
{
return x < zero;
}
static bool isTypeBig(int x)
{
// Из-за static zero не будет видно внутри функции
return x > zero;
}
int[] a = [ 1, 2, 3, 4, -5, 3, -4 ];
// Найти первое отрицательное число
auto b = find!(isTypeLow)(a).dup;
writeln(b);
auto c = find!(isTypeBig)(b);
writeln(c);
}