Closed ufcpp closed 1 year ago
using System.Runtime.CompilerServices;
// VB、呼ぶ側の文法に対応しなくても、
// 普通の構造体生成 → メソッド呼びならできそうな予感はある。
int x = 1;
A a = new(ref x);
// A a = x; // VB ゆるゆる型変換ならこれ相当のコードで済むかも
a.M();
// explicit extension A for int {}
// 何かしら [Extension(Explicit )] なりなんなりの属性はつくと思う
[CompilerGenerated]
ref struct A
{
ref int reference;
public A(ref int r) => reference = ref r;
public void M() { }
}
static class AEx
{
public static void M(this int x) { }
}
// 議題: 数学ライブラリに extension types は使えるか
// 小題: 今の generic math で困っていること
Rational<Polynomial<float>> f = 1; // この、int リテラルからの変換が厳しい。
struct Polynomial<T> { }
struct Rational<T> { }
// これを救える extension は書けるかどうか。
// 議題: 数学ライブラリに extension types は使えるか
// 小題: unit of measure 行けるかどうか
// 岩永個人の感覚からすると、extension の有無はネックにならない
// むしろ、足りないのは別の部分。
// ここだけは extension property 書けるとありがたい可能性あり
double w = 10.kg;
double l = 3.m;
double t = 5.s;
double N = w * l / (t * t);
PhysicalValue<kg> w;
PhysicalValue<m> l;
PhysicalValue<s> t;
PhysicalValue<kg | m> t; // kg m に対して、 union 型でも使う?
// s^2 の分母の方はどうする?
PhysicalValue<kg | m, s | s> t; // union 使っちゃうと s | s == s だけど?
// 一方、PhysicalValue<kg | m> と PhysicalValue<m | kg> は同じ型?
extension PhysicalValue<Unit> for double
{
}
class kg { }
class m { }
class s { }
class s { }
// ソースジェネレーターようなので、ランタイムには残したくない
[Conditional("COMPILE_TIME_ONLY")]
class MyAttribute : Attribute
{
}
using System.Globalization;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
var s = new[]
{
"ab",
"bc",
"Ab",
"Bc",
};
// StringComparison のデフォルトは CurrentCulture です。
var ordered = s.Order();// StringComparer.Ordinal);
foreach (var item in ordered)
{
Console.WriteLine(item);
}
配信URL: https://youtube.com/live/JIZcffKVdfo?feature=share
https://twitter.com/kosmosebi/status/1633098750796214272
Visual Studio 17.6 Preview 2 の気配を多少感じるので、今週やってもまた来週やりそうな気もしつつ。 記念雑談。
ほんとにノープラン雑談? Extensions の話とか? Dealing with limited breaking changes in C# の話とか?