Does anyone knows a command that does nothing in c++?
I mean - a command that the compiler reads and ignores, for example, if I want to execute the following program:
let's call this command 'blank'
void main(){
int a=1,b=2;
int temp=a;
b>a ? temp=b:blank;
}
Note: I know I can simply do temp=temp or something, but that's not what I'm looking for...
#include <iostream>
#include <boost/optional.hpp>
using boost::optional;
optional<int> f(int a, int b)
{
if (a < b)
return optional<int>(a);
elsereturn optional<int>();//uninitialized
}
int main()
{
int a = 5, b = 10;
optional<int> c = f(a, b);
if (c.is_initialized())
std::cout << *c << std::endl;
else
std::cout << "c is uninitialized" << std::endl;
}
Note: I know I can simply do temp=temp or something, but that's not what I'm looking for...
OR you could just use if
1 2 3
int a=1, b=2, temp=a;
if(b > a)
temp = b;
Just to answer exactly what you're asking for I'd probably do something like Sleep(1);, but I imagine if there was anything that truly did do absolutely nothing (like a + b but without assigning it to anything) that the the compiler would recognise this and just remove it from the executable file.