1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
includefile(include/header)
COMMENT(manpage, section, releasedate, archive, short name)
manpage(binopsbase)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_)
(Binary Operators)
manpagename(BinopsBase)(Class template offering class-type binary operators)
manpagesynopsis()
bf(#include <bobcat/binopsbase>)nl()
manpagedescription()
Classes may overload binary operators. A class named tt(Derived) may
overload binary operators to suit its own needs. It could, e.g., allow two
tt(Derived) class objects to be added together, or it could define a
shift-operation given a tt(size_t) right-hand side (rhs) argument.
The available binary operators are *, /, %, +, -, <<, >>, &, |, and ^ (in this
man-page they are generically indicated as the `tt(@)' operator). In addition,
overloaded tt(operator<<) and tt(operator>>) for stream insertion and
extraction are frequently defined.
If a class tt(Derived) supports copy and/or move construction and if it offers
a swap member (tt(void Derived::swap(Derived &rhs))), and is publicly derived
from tt(FBB::BinopsBase<Derived>) then once tt(Derived) defines a member
verb(
void Class::operator@=(Rhs const &rhs) &&
)
defining the compound tt(@)-operator for anonymous, temporary tt(Derived)
objects and a tt(Rhs) type for its right-hand side operand the following
operators are also available:
verb(
Derived &operator@=(Rhs const &rhs) &
Derived operator@(Derived &&lhs, Rhs const &rhs);
Derived operator@(Derived const &lhs, Rhs const &rhs);
)
A similar procedure applies to the insertion and extraction
operators. Insertion and extraction operators become available once
tt(BinopsBase<Derived>) is declared a friend class of tt(Derived). To make
the insertion operator available a private member
verb(
void Derived::insert(std::ostream &out) const
)
must then also be defined, inserting the calling object into
tt(out). Analogously, to make the extraction operator available a private
member
verb(
void Derived::extract(std::istream &in)
)
must be defined extrating the calling object from tt(in).
manpagesection(INHERITS FROM)
--
manpagesection(OVERLOADED OPERATORS)
For each defined tt(Derived &&operator@=(Rhs const &rhs) &&), defined in
the class tt(Derived) the following operators are automatically also available:
verb(
Derived operator@(Derived &&lhs, Rhs const &rhs);
Derived operator@(Derived const &lhs, Rhs const &rhs);
)
and
verb(
Derived &operator@=(Rhs const &rhs) &;
)
The insertion operator becomew available once
verb(
void Derived::insert(std::ostream &out) const
)
(inserting the calling object into tt(out)) has been defined. Analogously,
the extraction operator becomes available after defining a private member
verb(
void Derived::extract(std::istream &in)
)
(extracting the calling object from tt(in)).
manpagesection(FRIEND DECLARATION)
To make the insertion and/or extraction operators available the class
tt(Derived) must also declare
verb(
friend FBB::BinopsBase<Derived>;
)
manpagesection(EXAMPLE)
verbinclude(../../binopsbase/driver/driver.cc)
manpagefiles()
em(bobcat/binopsbase) - defines the binary operator function templates
manpageseealso()
bf(bobcat/binops)(3),
bf(bobcat)(7)
manpagebugs()
None Reported.
includefile(include/trailer)
|