Skip to content

Instantly share code, notes, and snippets.

Nobuyuki Iwanaga ufcpp

Block or report user

Report or block ufcpp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ufcpp
ufcpp / vs16_2_p3.cs
Created Jun 26, 2019
Visual Studio 16.2 Preview 3 がらみ
View vs16_2_p3.cs
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
// notnull 制約は 16.2.P3 から対応してそう。
// ただ、Visual Studio 上ではコード補完、ハイライト効いてない。
class C<T>
where T : notnull
{
public T Value { get; }
View ParseNumber.cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Linq;
using System.Runtime.CompilerServices;
public class Program
{
private const byte X = 0xff;
private static ReadOnlySpan<byte> DigitTableROS => new byte[] { X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, X, X, X, X, X, X, X, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, X, X, X, X, X, X, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, X, X, X, X, X, };
@ufcpp
ufcpp / WhiteNoise.cs
Created Jun 20, 2019
平均0の一様乱数で作った数列は自己相関関数がδ関数になる
View WhiteNoise.cs
using System;
using System.Linq;
class Program
{
static void Main()
{
const int N = 1 << 10;
const int Mask = N - 1;
@ufcpp
ufcpp / DimReabstraction.cs
Created Jun 13, 2019
Visual Studio 16.2 Preview 2 から実装入ってそう
View DimReabstraction.cs
using System;
interface A
{
void M() => Console.WriteLine("default implementation");
}
interface B : A
{
abstract void A.M();
@ufcpp
ufcpp / Comparison.cs
Created Jun 10, 2019
enum に応じて <, <=, >, >=, ==, != 分岐
View Comparison.cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Linq;
enum Comparison
{
Equal = 1,
Less = 2,
LessEqual = 3,
@ufcpp
ufcpp / DeconstructBenchmark.cs
Created Jun 9, 2019
インターフェイスを介するかどうかの差
View DeconstructBenchmark.cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
interface IDeconstructibleTo2Ints
{
void Deconstruct(out int x, out int y);
}
struct Point : IDeconstructibleTo2Ints
{
@ufcpp
ufcpp / NullableSafeOnly.cs
Created May 15, 2019
#nullable ディレクティブの初期挙動
View NullableSafeOnly.cs
// #nullable ディレクティブの初期挙動。
// VS 16.2 の辺りで実装変わりそう。
class Program
{
static void Main()
{
#nullable enable
// 警告きっちり出すモード
string s1 = null; // この行に CS8600 警告
@ufcpp
ufcpp / EnumeratorCancellation.cs
Created May 7, 2019
非同期イテレーターへの CancellationToken の伝搬(16.1 Preview 3)
View EnumeratorCancellation.cs
// 16.1 Preview 3 での挙動:
// X1(c1) → c1 が渡る
// X1(c1).WithCancellation(c2) → c2 が渡る
// X1(c1).WithCancellation(default) → c1 が渡る
// X1() → default が渡る
// X1().WithCancellation(c2) → c2 が渡る
//
// X2() → default, default が渡る
// X2(c1, c2) → c1, c2 が渡る
// X2(c1, c2).WithCancellation(default) → c1, c2 が渡る
@ufcpp
ufcpp / ConstDecimal.cs
Created Apr 17, 2019
もしやと思ってやってみたら Binary の方がほんのちょっと(1% くらい)速いの受ける
View ConstDecimal.cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Runtime.InteropServices;
public class DecimalConstantBenchmark
{
const int N = 10000;
const decimal ConstDecimal = 123456789.123456789m;
@ufcpp
ufcpp / SwitchExpressionInVs16_0.cs
Created Apr 3, 2019
C# 8.0 preview in VS 2019 (16.0) の注意点
View SwitchExpressionInVs16_0.cs
struct X
{
public int Value;
public X(int value) => Value = value;
// + と & で全く同じ処理を書いとく
public static X operator +(X x, X y) => new X(x.Value + y.Value);
public static X operator &(X x, X y) => new X(x.Value + y.Value);
public static explicit operator X(int x) => new X(x);
You can’t perform that action at this time.