Closed ufcpp closed 2 years ago
// C# でも整数型引数はほしい時なくはない
struct FixedArray<T, int N>
{
private T _items[N];
}
// 今、やっつけ大体案として…
var array = new FixedArray<int, object[,,,]>();
// new FixedArray<int, 4> のつもり
// generic attribute はいつの間にか requires preview features 外れてる。
[A<int>] // これは OK
[A<T>] // ダメ
[B(typeof(T))] // この時点でダメ
class X<T>
{
}
class AAttribute<T> : Attribute { }
class BAttribute : Attribute
{
public BAttribute(Type t) { }
}
public readonly struct Int32
: IAdditionOperators
{
}
// 別件として、associated type を考えてる
// self 制約を考えるのであればこれが先。
// associated type がいつになるのかわかんないので、当面、self type ない。
interface IAdditionOperators
{
associated type T;
abstract static T operator +(T x1, T x2);
}
Int32 苦行
IAdditionOperators<Int32, Int32, Int32>,
IAdditiveIdentity<Int32, Int32>
IBinaryInteger<Int32>
IBinaryNumber<Int32>
IBitwiseOperators<Int32, Int32, Int32>
INumber<Int32>
IComparable,
IComparable<Int32>
IComparisonOperators<Int32, Int32>
IEqualityOperators<Int32, Int32>
IEquatable<Int32>
IDecrementOperators<Int32>
IDivisionOperators<Int32, Int32, Int32>
IFormattable, IIncrementOperators<Int32>
IModulusOperators<Int32, Int32, Int32>
IMultiplicativeIdentity<Int32, Int32>
IMultiplyOperators<Int32, Int32, Int32>
IParseable<Int32>
ISpanFormattable,
ISpanParseable<Int32>
ISubtractionOperators<Int32, Int32, Int32>
IUnaryNegationOperators<Int32, Int32>
IUnaryPlusOperators<Int32, Int32>
IShiftOperators<Int32, Int32>
IConvertible,
IMinMaxValue<Int32>
ISignedNumber<Int32>
interface I
{
public static bool operator ==(I x1, I x2) => true; // non-virtual は多分認めない
abstract static bool operator ==(I x1, I x2); // 行けるようにするかも
public virtual static bool operator ==(I x1, I x2) => true; // 行けるようにするかも
}
// C# 3.0 の頃からこんな感じのコード、有効
// Q. これ、static abstract/型引数に対してもできるべき?
// A. できるべきだとは思う。今できないのは意図的じゃない。
// ****でも、需要なさそうだし作業したくない****
var x = from a in X where true select a;
// こうなる↓
var x1 = X.Where(a => true);
static class X
{
public static int Where(Func<string, bool> _) => 0;
}
interface I
{
abstract static int Where(Func<string, bool> _);
}
void m<T>()
where T : I
{
// これがダメらしいよ。
// (リスナー全員満場一致で「ダメでいいだろ」)
var x = from a in T where true select a;
}
// Q. 以下のうち、エラーになる行をこたえよ
Console.WriteLine($"""{1}""");
Console.WriteLine($"""{{1}}""");
Console.WriteLine($$"""{{1}}""");
Console.WriteLine($$"""{{{1}}}""");
Console.WriteLine($$$"""{{{1}}}""");
Console.WriteLine($$$"""{{{{1}}}}""");
_ = @"""a"""; // これ、普通の verbatim だわ…
配信URL: https://www.youtube.com/watch?v=4TiCd5ov_WI
そんなに良さげな話ないかも…
Preview 4 (core/issues/7378)に期待? C# 的にも、17.3 で u8 リテラルとか入るみたいで次に期待? (runtime に先行して u8 リテラル使ってみた PR あり runtime/pull/67733)
なのでまた Language Design Meeting Notes 読みかなぁ…
LDM
こっちも細かい話が多め。
話されてた内容:
class A : INumber<A>
みたいに、必ず「自分自身」を受けたい型引数required ref int X
みたいなの → A. 需要なさそう。やめとく==
,!=
は持てる? → A. 持てるようにする (一方、non-virtual な==
は引き続き持てない)static I I.operator +(I x)
とかでいい? → A. いいfile
修飾子」になりそうfile
は単独でしか掛けないアクセス修飾子にするfile protected
とかも有効: this()
S(int)
実行 の順が濃厚!!
以外を考える? →!
はない。かといって他の案(T parameter not null
みたいなの)は長ったらしかったりできつい