我有一个关于如何编写一行具有最大数量的唯一保留字的 C++ 代码的长期思想实验。在这个挑战中,您可以随意复制关键字,但重要的是您使用的唯一关键字的数量。例如,如果你写
void MyFunction(int, int, int, int);
有四个 int 实例,但上面一行的得分为 2,因为它只有两个唯一的关键字(void
和int
,即)。不过这条线,
void MyFunction(int, double, short, long);
五个保留字的得分为 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();
其中包含多达 39 个保留字。不过,它假定您在声明它之前已经定义了enum MyEnum
, struct MyStruct
, and 。union MyUnion
是的,如果您在使用它之前设置了适当的类型,它确实可以编译(尽管它确实给出了关于 . 的警告。)g++
export
我很好奇是否有人看到任何方法可以将更多独特的关键字塞进一行代码。有人可以顶我的例子吗?还是想办法让它变得更加邪恶?
我知道 C++ 是自由形式的,所以“代码行”并不是一个很好的结构衡量标准,但我认为我们可以对这意味着什么做出合理的解释。
编辑:刚刚添加throw()
到函数的末尾以获得更多的关键字。