Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you replace & with bitand in references?

Tags:

c++

syntax

c++11

In C++, we can write and for &&, or for ||, bitand for & and bitor for |.

Now I wonder whether and and bitand are only valid where those operators are meant, or also where references are defined (g++ 4.6.3 accepts bitand for references — rvalue references seem not to be supported in that version — but of course that might just be the compiler not catching the error).

In short: Is the following code valid C++?

int and x = 3;

int a;
int bitand y = a;

Of course I would never write such code (except maybe if participating in an obfuscated code contest), but is it actually valid?

like image 312
celtschk Avatar asked Jun 08 '13 22:06

celtschk


People also ask

Can be replaced meaning?

to take the place of something, or to put something or someone in the place of something or someone else: The factory replaced most of its workers with robots.

What word can I use instead of replace?

Some common synonyms of replace are displace, supersede, and supplant.

What is an example of replace?

Example SentencesPaper bags have been largely replaced by plastic bags. She was hired to replace the previous manager. I replaced the old rug with a new one.


1 Answers

According to C++11, 2.6/4:

In all respects of the language, each alternative token behaves the same, respectively, as its primary token

So int and a = 5; is perfectly valid, though also perfectly insane.


More examples:

struct ete
{
    compl ete();
    int egr()and;
};
like image 57
Kerrek SB Avatar answered Oct 06 '22 05:10

Kerrek SB