tem*_*def 2 c++ puzzle reserved-words
我有一个关于如何编写一行C++代码的长期思想实验,该代码中包含最大数量的唯一保留字.在此挑战中,您可以根据需要复制关键字,但重要的是您使用的唯一关键字的数量.例如,如果你写
void MyFunction(int, int, int, int);
Run Code Online (Sandbox Code Playgroud)
有四个int实例,但上面的行得分为2,因为它只有两个唯一的关键字(void
和int
,即).不过这条线路
void MyFunction(int, double, short, long);
Run Code Online (Sandbox Code Playgroud)
五个保留字的得分为5分.
到目前为止,我能够想到的最好的是
export template <typename T, class C>
inline void DiabolicalFunc (int, char, short,
long, double, signed,
unsigned, bool, float,
wchar_t, const int,
volatile int,
enum MyEnum,
void* (*)(size_t) = &(operator new),
void (*)(void*) = &(operator delete),
int = const_cast<int*>(static_cast<const int *>(reinterpret_cast<int*>(0))),
void* = dynamic_cast<void*>(reinterpret_cast<ios_base*>(0)),
bool = true, bool = false, int = sizeof(int),
const std::type_info& = typeid(int),
struct MyStruct = MyStruct(), union MyUnion = MyUnion(),
int = 0 and 0,
int = 0 bitand 0,
int = 0 bitor 0,
int = compl 0,
int = not 0,
int = 0 not_eq 0,
int = 0 or 0,
int = 0 xor 0) throw();
Run Code Online (Sandbox Code Playgroud)
这里有39个保留字.它假定您已经定义了一个enum MyEnum
,struct MyStruct
和union MyUnion
它声明,虽然之前.是的,如果你在使用它之前设置了适当的类型,它确实可以编译g++
(尽管它确实会发出警告export
.)
我很好奇,如果有人看到任何方法将更多独特的关键字塞进一行代码中.有人可以成为我的榜样吗?或者找到一种让它变得更恶魔的方法?
我知道C++是自由形式的,因此"代码行"并不是一个非常好的结构度量,但我认为我们可以对这意味着什么进行合理的解释.
编辑:刚添加throw()
到函数的末尾,以获得一个更多的关键字.
GMa*_*ckG 10
你说的一行C++代码?
// asm auto bool break case catch char class const ...
Run Code Online (Sandbox Code Playgroud)
我小子,我小子.