Closed ufcpp closed 9 months ago
API diff の見た目がえぐい
(改行してないせい。実際の差分は , IUtf8SpanParsable<byte>
だけ。)
DegreesToRadians
using System.Globalization;
using System.Numerics;
Console.WriteLine(parse<int>("123"u8));
Console.WriteLine(parse<byte>("123"u8));
// string と bool はこのインターフェイスも、
// string の方の ISpanFormattable/Parsable も実装してない
Console.WriteLine(parse<string>("123"u8));
Console.WriteLine(parse<bool>("true"u8));
// Complex の書式わかんねぇ
Console.WriteLine(parse<Complex>("123 256"u8));
static T parse<T>(ReadOnlySpan<byte> s)
where T : IUtf8SpanParsable<T>
=> T.Parse(s, CultureInfo.InvariantCulture);
// 現状、new string[3] になっちゃう。
// GA までには、InlineArray 化する予定。
Span<string> a = ["", "a", "abc"]; // stackalloc 化無理
ImmutableArray<string> s = [""]; // F12 で ImmutableArray.Create に飛べてほしい
List<int> list;
_ = list[1]; // それでいうと、インデクサーも F12 で飛べてほしい。
static void X1(IEnumerable<int>? a)
{
// ここ、target-type が IEnumerable なので、 [] は Empty 最適化かかる予定
foreach (var x in a ?? [])
{
Console.WriteLine(x);
}
}
static void X2(List<int>? a)
{
// こっちで同じことやると、Empty 最適化かからない可能性大なのでは…
foreach (var x in a ?? [])
{
Console.WriteLine(x);
}
}
List.Empty 必要?
Case Preserving 置換、コピペからの整形で便利かも。
static async ValueTask MAsync()
{
{
Span<int> x; // これダメ。
M1(stackalloc int[1]); // これは行けるのに。
}
await Task.Delay(1);
}
static IEnumerable<object> MIterator()
{
Span<int> x = default; // これ、平気。
M1(x);
yield return null;
// イテレーターの場合は yield をまたいだ瞬間にエラー。
//foreach (var item in x) { }
}
static void M1(Span<int> x) { }
17.7 も GA したし振り返る?
C# /.NET 関連:
ImmutableArray<int> a = [1, 2, 3, 4, 5];
がちゃんと想像通りに動くように[]
をArray.Empty
にする最適化とか