Title: Theory / Unimportant / CS / Programming / C++ / Manual / Norm / 18 Operator
Tags: automatedNewLineAfterCommaSpace declaration todo_declaration Copy syntactical_sugar

Page: 528
Effect: expr_1.operatorOP(expr_2) or operatorOP(exp_1, expr_2)
Language: C++
Chapter: 18
Section: 1
Abbreviation: expr_1 OP expr_2

Question: What are the differenc between default operators and user-defined operators
Answer: user defined "&&", and "||" do not lead to shortcut as boolean does
Page: 529
Chapter: 18
Section: 2
Answer2: += and ++ are not defined in term of + by default

Question: Why is it useful to get operator which are non member function
Answer: To define int + complex, you can't define + as a member of int, so you need a non operator method
Page: 529
Chapter: 18
Section: 2

Question: what is good practice for OP= operator
Answer: Modifying the left input and returning a reference to it
Page: 534
Chapter: 18
Section: 2

Question: what is good practive for infix operator
Answer: inputs are constant
Page: 534
Chapter: 18
Section: 2
Answer2: output is a value

Question: How to determine which binary operator to use for x@y
Answer: if x's class is X, and X has operator@(Y), then use it
Page: 534
Chapter: 18
Section: 2
Answer2: otherwise check for
operator(X, Y) in context of the call
Answer3: otherwise check for
operator(X, Y) in namespace of X's definition
Answer4: otherwise check for
operator(X, Y) in namespace of Y's definiton

Instruction: TO_CLASS::operator FROM_CLASS(FROM_CLASS input) {
  ...
}
Page: 543
Effect: The method used to convert FROM_CLASS to TO_CLASS
Language: C++
Chapter: 18
Section: 2
Extra: there is no return type in the declaration. It is TO_CLASS

Instruction: int operator()(args) {
  foo
}
Page: 551
Effect: same as
int function_name(args) {
  foo
}
But the function is called by applying to an object of type C
Language: C++
Chapter: 19
Section: 2
Variables: class C

Name: The call operator
Definition: (arg_1, ..., arg_n) considered as an operator applied to a callable
Page: 551
Chapter: 19
Section: 2.2
Name2: The application operator

Instruction: ptr->bar
Page: 552
Language: C++
Chapter: 19
Section: 2.2
Returns: (*ptr).bar
Variables: ptr a pointer
Name: The arrow operator

Instruction: foo->bar
Page: 552
Language: C++
Chapter: 19
Section: 2.2
Returns: (foo.operator->())->bar
Assuming: foo not a pointer
Name: The arrow operator

Question: Constraint on operator->
Answer: Returns a pointer
Page: 553
Chapter: 19
Section: 2.2
Answer2: is defined as non static member

Instruction: operator++() {
 foo
}
Page: 553
Meaning: Define the prefix operator ++ to do foo
Language: C++
Chapter: 19
Section: 2.2

Instruction: operator++(int) {
 foo
}
Page: 553
Meaning: Define the postfix operator ++ to do foo.
Language: C++
Chapter: 19
Section: 2.2
Extra: Argument is only useful to desambiguate from prefix operator

Instruction: void* operator new(size_t) {
 foo(size_t)
}
Page: 557
Effect: new Class, will execute foo(sizeof(Class))
Language: C++
Context: Not in a class
Chapter: 19
Section: 2.2

Instruction: void* operator new(size_t) {
 foo(size_t)
}
Page: 557
Effect: new Derived, with Derived deriving Base, will execute foo(sizeof(Derived))
Language: C++
Chapter: 19
Section: 2.2
Variables: class Base

Instruction: void* operator new[](size_t) {
 foo(size_t)
}
Page: 557
Effect: new Class[n], will execute foo(n*sizeof(Derived))
Language: C++
Context: not in a class
Chapter: 19
Section: 2.2

Instruction: void* operator new[](size_t) {
 foo(size_t)
}
Page: 557
Effect: new Derived[n]
with Derived deriving Base, will execute foo(n*sizeof(Derived))
Language: C++
Chapter: 19
Section: 2.2
Variables: class Base

Instruction: void operator delete[](
  pointer,
  size_t
) {
 foo(pointer, size_t)
}
Page: 557
Effect: delete pointer[] execute foo(pointer, length(pointer)*sizeof(Derived))
Language: C++
Context: not in a class
Chapter: 19
Section: 2.2

Instruction: void operator delete[](
  pointer,
  size_t
) {
 foo(pointer, size_t)
}
Page: 557
Effect: delete pointer[]
with pointer of type deriving Base, will execute foo(pointer, length(pointer)*sizeof(Derived))
Language: C++
Chapter: 19
Section: 2.2
Variables: class Base

Instruction: void operator delete(
  pointer,
  size_t
) {
 foo(pointer, size_t)
}
Page: 557
Effect: delete pointer
execute foo(pointer, sizeof(class(pointer)))
Language: C++
Context: Not a class
Chapter: 19
Section: 2.2

Instruction: void operator delete(
  pointer,
  size_t
) {
 foo(pointer, size_t)
}
Page: 557
Effect: delete pointer
with pointer of type deriving Base, will execute foo(pointer, sizeof(class(pointer)))
Language: C++
Chapter: 19
Section: 2.2
Variables: class Base

Instruction: operator"" suffix(some_number)
Page: 558
Language: C++
Chapter: 19
Section: 2.6
Abbreviation: some_numbersuffix

Instruction: operator"" suffix(
  "some text",
  text_length
)
Page: 558
Language: C++
Chapter: 19
Section: 2.6
Name: A user-defined literal
Abbreviation: "some text"suffix

Instruction: type operator"" suffix(
  char* c,
  size_t n
) {
  foo
}
Page: 558
Meaning: "bar"suffix is created by executing foo
Language: C++
Chapter: 19
Section: 2.6
Name: a literal operator

Instruction: type operator"" suffix(numeric_type val) {
  foo
}
Page: 558
Meaning: some_numbersuffix is created by executing foo with argument some_number
Language: C++
Chapter: 19
Section: 2.6

Question: What are the acceptable user-defined literal suffix
Answer: anything starting with a _
Page: 561
Chapter: 19
Section: 2.6

Question: If an argument may be potentially muted, should it be passed by value or reference
Answer: reference
Page: 532
Chapter: 18
Section: 2

Question: If an argument is accessed rarely, should it be passed by value or reference
Answer: reference, the extra cost to dereference may be acceptable
Page: 532
Chapter: 18
Section: 2

Question: If an argument is more than four words, should it be passed by value or reference
Answer: reference is cheaper as it avoids copy
Page: 532
Chapter: 18
Section: 2

Question: If a copy/move is expensivte, should it be passed by value or reference
Answer: reference is cheaper as it avoids copy
Page: 532
Chapter: 18
Section: 2