OpenSiv3D icon indicating copy to clipboard operation
OpenSiv3D copied to clipboard

各種クラスの fmt 対応の不具合

Open Reputeless opened this issue 2 years ago • 3 comments

  • reported by: https://discord.com/channels/443310697397354506/1000291580915232879/1013121181500588123

Reputeless avatar Aug 28 '22 06:08 Reputeless

Optional についても同様の不具合があります。 format_to(ctx.out(), sv) で検索をかけるといくつか出てきましたが、 DateIPv4Address などは {} が出てこないので問題なさそうです。 ArrayGrid{} をそれぞれ {{}} に置換することで解決していますが、 replace メンバ関数の呼び出しのたびに要素のコピーが発生しているので、パフォーマンスに影響が出てそうです。この機会に改めるのもいいかもしれません。

format_to(ctx.out(), sv) で検索して出てきたクラス

  • String
  • StringView
  • Optional
  • Date
  • DateTime
  • IPv4Address
  • UUIDValue
  • Array
  • Grid
# include <Siv3D.hpp> // OpenSiv3D v0.6.5

void Main()
{
	Print << U"{}"_fmt(U"{}"s);              // std::u32string は OK
	Print << U"{}"_fmt(Optional{ U"{}"s });  // Optional<std::u32string> はダメ

	while (System::Update());
}

Raclamusi avatar Aug 28 '22 07:08 Raclamusi

ご指摘ありがとうございます!

Reputeless avatar Aug 28 '22 07:08 Reputeless

開発中の v0.6.6 で修正

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	Console << U"{}"_fmt(U"{}");
	Console << U"{}"_fmt(U"{}"_s);
	Console << U"{}"_fmt(U"{}"_sv);
	Console << U"{}"_fmt(Optional{ U"{}"s });

	{
		Array<int32> e = {};
		Console << U"Hello {} array"_fmt(e);

		Array<int32> v = { 1, 2, 3, 4, 5 };
		Console << U"Hello {} array"_fmt(v);

		Array<String> vs = { U"Aaa", U"Bbb", U"{}", U"Ddd" };
		Console << U"Hello {} array"_fmt(vs);

		Array<double> vd = { 1.23456, 2.2222, 3.33333, 4.4444, 5.55555 };
		Array<Array<double>> vvd = { vd, vd, {} };
		Console << U"{:.1f}"_fmt(vvd);
	}

	{
		Grid<int32> e;
		Console << U"Hello {} array"_fmt(e);

		Grid<int32> v(Size{ 3, 4 }, 1);
		Console << U"Hello {:#x} array"_fmt(v);

		Grid<String> vs = { {U"Aaa", U"Bbb"}, {U"{}", U"Ddd"} };
		Console << U"Hello {} array"_fmt(vs);

		Grid<double> vd = { {1.23456, 2.2222}, {3.33333, 4.4444}, {5.55555, 6.66} };
		Grid<Grid<double>> vvd(Size{ 2, 2 }, vd);
		Console << U"{:.1f}"_fmt(vvd);
	}

	{
		std::vector<int32> e = {};
		Console << U"Hello {} array"_fmt(e);

		std::vector<int32> v = { 1, 2, 3, 4, 5 };
		Console << U"Hello {} array"_fmt(v);

		std::vector<String> vs = { U"Aaa", U"Bbb", U"{}", U"Ddd" };
		Console << U"Hello {} array"_fmt(vs);

		std::vector<double> vd = { 1.23456, 2.2222, 3.33333, 4.4444, 5.55555 };
		std::vector<std::vector<double>> vvd = { vd, vd, {} };
		Console << U"{:.1f}"_fmt(vvd);
	}

	{
		std::array<int32, 0> e = {};
		Console << U"Hello {} array"_fmt(e);

		std::array<int32, 5> v = { 1, 2, 3, 4, 5 };
		Console << U"Hello {} array"_fmt(v);

		std::array<String, 4> vs = { U"Aaa", U"Bbb", U"{}", U"Ddd" };
		Console << U"Hello {} array"_fmt(vs);

		Array<double> vd = { 1.23456, 2.2222, 3.33333, 4.4444, 5.55555 };
		std::array<Array<double>, 3> vvd = { vd, vd, {} };
		Console << U"{:.1f}"_fmt(vvd);
	}

	while (System::Update())
	{

	}
}

Reputeless avatar Sep 01 '22 04:09 Reputeless