花里胡哨的代用记号与三标符
紫陰花
2019-08-23 10:15:39
前言:
作者完全是出于兴趣瞎写了一篇文章投稿的,没想到真发表了。
本文几乎毫无学术价值,请勿引战。
广告:[洛谷定律&名词](/blog/WARNING/luo-gu-ding-lv-ming-ci) [关于她们......](/blog/WARNING/xx-shi-post)
---
# 关于代用记号
是不是`&`,`|`,`^`什么的都用习惯了?
代用记号让你~~感叹道还是原来的好新的太长了记都记不住~~
喏,它们就长这个亚子:
```cpp
and
and_eq
or
or_eq
xor
xor_eq
not
not_eq
bitand
bitor
compl
<%
%>
<:
:>
%:
%:%:
```
![](http://a2.qpic.cn/psb?/V12mbD9F3HnatE/FRi*1as1ZhxfEaIEgXT0MeeBIZs9vqy3AdjIafr*XuA!/c/dAUBAAAAAAAA&ek=1&kp=1&pt=0&bo=8ADqAAAAAAAAADw!&tl=3&vuin=2138527518&tm=1564545600&sce=60-2-2&rf=0-0)
都什么鬼东西啊!
~~但有没有一种似曾相识的感觉?~~
~~英文学得如何啊?~~
这些新代用记号能与原有的操作符完美替换,直接改不会有任何问题
~~我觉得这种代用记号的好处在于可读性加强了,毕竟英语大家都能看懂,一些奇奇怪怪的符号也只有OIer能出手了(那后面六个……)~~
![](https://cn.bing.com/th?id=OIP.e5Rlwv0YJ80tokh5BrUSDgAAAA&pid=Api&rs=1&p=0)
---
## and
表示逻辑与操作,等价于`&&`操作符,可直接替换
```cpp
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
if(n==m and m==k)//将这里的and改为&&也可通过
printf("Yes\n");
else
printf("No\n");
```
---
## and_eq
表示相与并赋值,等价于`&=`操作符(不常用?)
```cpp
char n,m;
cin>>n>>m;
n and_eq m;
cout<<n;
```
---
## or
表示逻辑或,等价于`||`操作符
```cpp
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
if(n==m or m==k)
printf("Yes\n");
else
printf("No\n");
```
---
## or_eq
表示相或并赋值,等价于`|=`操作符(不常用?)
```cpp
char n,m;
cin>>n>>m;
n or_eq m;
cout<<n;
```
---
## xor
表示逻辑异或,等价于`^`操作符
```cpp
int a,b;
scanf("%d%d",&a,&b);
printf("%d",int(a xor b));
```
---
## xor_eq
表示相异或并赋值,等价于`^=`操作符
```cpp
int a,b;
scanf("%d%d",&a,&b);
a xor_eq b xor_eq a xor_eq b; //等价于a^=b^=a^=b;
//这段代码相当于swap(a,b);
printf("%d %d",a,b);
```
---
## not
表示逻辑非, 等价于`!`操作符
```cpp
srand(time(NULL));
queue<int> q;
int b=rand()%32+1;
for(int i=1;i<=b;i++)
q.push(rand()%32);
while(not(q.empty()))
{
printf("%d\n",q.front());
q.pop();
}
```
---
## not_eq
等价于`!=`操作符
```cpp
int a,b;
scanf("%d%d",&a,&b);
if(a not_eq b)
printf("Yes");
else
printf("No");
```
---
## bitand, bitor
与`and`,`or`类似,不过是按位操作,`bitand`等价于`&`,`bitor`等价于`|`
?)断词:`bit and`,`bit or`
---
## compl
按位取反 等价于`~`操作符
~~那以后打删除线时是不是要complcompl内容complcompl~~
```cpp
int a;
scanf("%d",&a);
printf("%d",int(compl a));
```
~~重头戏要来了!~~
![](https://cdn.luogu.com.cn/upload/pic/75372.png)
---
## <%,%>
相当于大括号`{`,`}`
~~越来越诡异了~~
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
<%
%>
```
---
## <:,:>
相当于中括号`[`,`]`
~~太诡异了吧~~
```cpp
#include<bits/stdc++.h>
using namespace std;
int x<:50:>;
int main()
{
cin>>x<:1:>;
cout<<x<:1:>;
}
```
---
## %:,%:%:
相当于`#`,`##`
```cpp
%:include<bits/stdc++.h>
using namespace std;
%:define maxx 500
%:define F(i,a,b) for(register int i=a,i%:%:_end=b;i<=i%:%:_end;++i)//用##卡常?
int f[maxx];
int main()
{
}
```
---
## 一些摘录:
当分析器遇到字符序列`<::`,且后继字符既非`:`亦非`>`时,`<`被当做预处理记号本身,而非代用记号`<:`。从而`std::vector<::std::string>`不会被错误地处理成`std::vector[:std::string>`。(`C++11`起)
注解
字符`&`及`!`在`ISO-646`下不变,但仍然为使用这些字符的记号提供了代用写法,以便能够适应更加受限的历史字符集。
没有相等运算符的代用拼写`==`如`eq`),因为字符`=`已在所有受支持字符集中存在。
与`C`的兼容性
`C`编程语言中,同样的单词作为宏定义于包含文件`<iso646.h>`之中。因为`C++`中它们内建于语言,故`<iso646.h>`的`C++`版本还有`<ciso646>`不定义任何内容。
---
## 另附:各种代用记号的综合使用
**P1100**:
```cpp
%:include<bits/stdc++.h>
%:define maxn 50
char x<:maxn:>;
int main()
<%
long long a,ans=0,b;
int i;
scanf("%lld",&a);
for(i=0;i<32;i++)
x<:i:>=char(a%2+'0'),a/=2;
for(i=0;i<16;i++)
x<:i:> xor_eq x<:i+16:> xor_eq x<:i:> xor_eq x<:i+16:>;
for(i=0,b=1;i<32;i++,b*=2)
ans+=int(x<:i:>-'0')*b;
printf("%lld",ans);
%>
//写的我头都晕了……
```
---
## 代用记号:简易对照表
```cpp
and &&
and_eq &=
or ||
or_eq |=
xor ^
xor_eq ^=
not !
not_eq !=
bitand &
bitor |
compl ~
<% {
%> }
<: [
:> ]
%: #
%:%: ##
```
---
# 关于三标符:
~~感觉没有用,按照cppreference.com上面的说法,这东西在C++17时被移除了~~ 但是还是要看一下的 ~~为了凑篇幅~~
对于这些东西不详细描述,直接给出对应表:
```cpp
??< {
??> }
??( [
??) ]
??= #
??/ \
??' ^
??! |
??- ~
```
---
## 摘录:
因为三标符的处理非常早,所以如`// Will the next line be executed?????/`这样的注释实际上会注释掉下一行,而如`"Enter date ??/??/??"`这样的字符串字面量将被分析为`"Enter date \\??"`。
~~总结:这些东西没用~~
---
### 参考文献:
1.[C++11新特性之and, and_eq, or, or_eq, xor, xor_eq, not, not_eq操作符](https://blog.csdn.net/oyoung_2012/article/details/78718226)
2.[代用运算符表示](https://zh.cppreference.com/w/cpp/language/operator_alternative)