关于类模板的重载括号运算符怎么指定类型
  • 板块学术版
  • 楼主蒟酱厂妹
  • 当前回复18
  • 已保存回复18
  • 发布时间2022/5/9 14:56
  • 上次更新2023/10/28 01:49:54
查看原帖
关于类模板的重载括号运算符怎么指定类型
310818
蒟酱厂妹楼主2022/5/9 14:56
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
class fastIO
{
private:
	char ibuf[1000007], *p1 = ibuf, *p2 = ibuf;
	char get() { return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1000007, stdin), p1 == p2) ? EOF : *p1++; }

public:
	template <typename any>
	typename std::enable_if<(std::is_signed<any>::value && std::is_integral<any>::value && !std::is_same<any, char>::value) || std::is_same<any, __int128_t>::value, any>::type tpval()
	{
		any t = 0;
		bool y = 0;
		char c = get();
		for (; !isdigit(c); c = get())
			if (c == 45)
				y = true;
		for (; isdigit(c); c = get())
			t = t * 10 + c - 48;
		if (y == 1)
			t = -t;
		return t;
	}
	template <typename any>
	typename std::enable_if<(std::is_signed<any>::value && std::is_integral<any>::value && !std::is_same<any, char>::value) || std::is_same<any, __int128_t>::value, any>::type operator()()
	{
		any t = 0;
		bool y = 0;
		char c = get();
		for (; !isdigit(c); c = get())
			if (c == 45)
				y = true;
		for (; isdigit(c); c = get())
			t = t * 10 + c - 48;
		if (y == 1)
			t = -t;
		return t;
	}
} fio;
signed main()
{
	int t1 = fio.tpval<int>();
	int t2 = fio.operator()<int>();
	return 0;
}

比如说我有这么一段代码,这里的快读有成员函数形式和重载运算符括号形式,这样都不会 CE,但是重载运算符的非函数形式(也就是常用的那种形式)怎么写
经过测试以下 5 个写法均 CE

fio()<int>;
fio<int>();
fio<int>()();
fio()<int>();
fio()()<int>;
2022/5/9 14:56
加载中...