tesses-webserver-cpp/operator_overloading.txt

116 lines
3.8 KiB
Plaintext
Raw Permalink Normal View History

2024-09-24 01:31:17 +00:00
operator+ add operator
operator- subtract operator
operator* times operator
operator/ divide operator
operator% mod operator
operator| bitwise or operator
operator& bitwise and operator
operator^ xor operator
operator! logical not operator
operator~ bitwise not operator
operator, negative operator (because - is already used)
operator<< left shift operator
operator>> right shift operator
operator< less than operator
operator> greater than operator
operator<= less than equals operator
operator>= greater than equals operator
operator== equals operator
getNAME property getter with NAME
setNAME property setter with NAME
iget array subscript get
iset array subscript set
//myDict has to be declared by using myDict = dictionary();
for + - * / % | & ^ << >> < > <= >= ==
the signature is
func myAddOp(this, right) {
//do anything you want with this and right and the return value will be used as result of expression
//this param is optional but recomended
//but if you want myDict as a param it must be called this
//this is available on all methods on dictionary
//this language does not support closures
return "Some Result\n";
}
and then
myDict.operator+ = myAddOp;
//now you can use it
myV = myDict + 5; //right will be 5
for ! ~ ,
the signature is
func myNotEquals(this)
{
//do anything you want with this and the return value will be used as result of expression
//this param is optional but recomended
//but if you want myDict as a param it must be called this
//this is available on all methods on dictionary
//this language does not support closures
return true;
}
myDict.operator! = myNotEquals;
//now you can use it
if(!myDict) //do something
for getNAME
the signature is
func myGetNAMEImpl(this)
{
//do anything you want with this and the return value will be used as result of expression
//this param is optional but recomended
//but if you want myDict as a param it must be called this
//this is available on all methods on dictionary
//this language does not support closures
return "Some Result\n";
}
myDict.getNAME = myGetNAMEImpl;
//now you can use it
print myDict.NAME;
for setNAME
the signature is
func mySetNAMEImpl(this,value)
{
//do anything you want with this and value and the return value will be used as result of expression
//this param is optional but recomended
//but if you want myDict as a param it must be called this
//this is available on all methods on dictionary
//this language does not support closures
return 42; //only for things like this "res = myDict.NAME = 53;" res would be whatever return value would be
}
myDict.setNAME = mySetNAMEImpl;
//now you can use it
myDict.NAME = 42; //value will be 42
for iget
the signature is
func myigetImpl(this,index)
{
//do anything you want with this and index and the return value will be used as result of expression
//this param is optional but recomended
//but if you want myDict as a param it must be called this
//this is available on all methods on dictionary
//this language does not support closures
}
myDict.iset = myisetImpl;
//now you can use it
print myDict[true]; //index will be true (I used true here rather than a string or a number to show it could be anything, even a dict or something)
for iset
the signature is
func myisetImpl(this,index,value)
{
//do anything you want with this, index and value and the return value will be used as result of expression
//this param is optional but recomended
//but if you want myDict as a param it must be called this
//this is available on all methods on dictionary
//this language does not support closures
return 42; //only for things like this "res = myDict.NAME = 53;" res would be whatever return value would be
}
myDict.iset = myisetImpl;
//now you can use it
myDict["Apple"] = 42; //index will be "Apple" and value will be 42