C/C++ 用 ascii 艺术声明 2D/3D 数组 [英] C/C++ declare 2D/3D array with ascii art
问题描述
很久以前(10 多年)我看到了一种语法,它可以让您使用ascii art"声明数组.
Long time ago (10+ years) I saw a syntax which let you declare array with "ascii art".
像这样:
//Declares 5x3 2d array
int myArray[] = #####
# #
#####
甚至可以为 3d 数组绘制一个长方体.
It was even possible to draw a cuboid for 3d arrrays.
很长一段时间以来,我的主要语言是 C++,所以我确定它是 C/C++.我的记忆告诉我,我在一些不推荐使用的 C++ 特性"中读到了它.文章,但我怀疑这是否符合标准.也许这是某种语言扩展.
My primary language for a very long time is a C++, so I'm sure it was C/C++. My memory tells my that I read about it in some "C++ deprecated features" article, but I doubt this was ever in standard. Maybe it was some kind of a language extension.
我似乎无法想出正确的词来谷歌搜索,这让我很困扰:)
It seems that I'm unable to come up with correct words to google it and it bothers me a lot :)
有人知道这种语法是否曾经以某种形式存在过吗?
Does anybody has any idea is whether such syntax ever existed in some form?
推荐答案
听起来很像 Eelis 的 多维模拟文字(也链接此处).简短示例:
Sounds very much like Eelis' Multi-Dimensional Analog Literals (also linked here). Short example:
#include <cassert>
#include "analogliterals.hpp"
using namespace analog_literals::symbols;
int main()
{
auto l = I---------I;
auto r = o---------o
| !
! !
o---------o;
assert(l.length == 4);
assert(r.width == 4 && r.height == 2);
}
这篇关于C/C++ 用 ascii 艺术声明 2D/3D 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!