/usr/share/doc/libbobcat4-dev/man/binopsbase.3.html is in libbobcat-dev 4.04.00-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | <!DOCTYPE html><html><head>
<meta charset="UTF-8">
<title>binopsbase</title>
<style type="text/css">
figure {text-align: center;}
img {vertical-align: center;}
</style>
<link rev="made" href="mailto:Frank B. Brokken: f.b.brokken@rug.nl">
</head>
<body text="#27408B" bgcolor="#FFFAF0">
<hr/>
<h1 id="title">binopsbase</h1>
<h2 id="author">libbobcat-dev_4.04.00-x.tar.gz</h2>
<h2 id="date">2005-2016</h2>
<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<style type="text/css">
figure {text-align: center;}
img {vertical-align: center;}
figure {text-align: center;}
img {vertical-align: center;}
</style>
<link rev="made" href="mailto:Frank B. Brokken: f.b.brokken@rug.nl">
</head>
<body text="#27408B" bgcolor="#FFFAF0">
<hr/>
<h1 id="title"></h1>
<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<title>binopsbase(3bobcat)</title>
<style type="text/css">
figure {text-align: center;}
img {vertical-align: center;}
figure {text-align: center;}
img {vertical-align: center;}
figure {text-align: center;}
img {vertical-align: center;}
</style>
<link rev="made" href="mailto:Frank B. Brokken: f.b.brokken@rug.nl">
</head>
<body text="#27408B" bgcolor="#FFFAF0">
<hr/>
<h1 id="title">binopsbase(3bobcat)</h1>
<h2 id="author">libbobcat-dev_4.04.00-x.tar.gz Binary Operators</h2>
<h2 id="date">2005-2016</h2>
<p>
<h2 >NAME</h2>binopsbase - Class template offering class-type binary operators
<p>
<h2 >SYNOPSIS</h2>
<strong >#include <bobcat/binopsbase></strong><br/>
<p>
<h2 >DESCRIPTION</h2>
Classes can overload binary operators. A class named <em >Class</em> may
overload these binary operators to suit its own needs, allowing, e.g., two
<em >Class</em> type objects to be added after overloading <em >operator+</em>. Operators
for the binary operators *, /, %, +, -, <<, >>, &, |, and ^ (in this man-page
they are generically indicated as the `<em >@</em>' operator) can be overloaded by
providing various <em >operator@</em> members and functions.
<p>
If a class supports copy and/or move construction and if it offers a swap
member, then binary operators can all be implemented identically, except for
the specific details associated with specific binary operators. E.g., if a
class contains two <em >int</em> data members addition of objects of that class
could simply be defined as adding the corresponding <em >int</em> members, while
subtraction could be defined as subtracting the corresponding <em >int</em>
members. Assuming the existence of a member <em >void Class::add(Class const
&rhs)</em> that defines the addition of a <em >Class rhs</em> object to the <em >*this</em>
object, while merely providing the basic exception guarantee (i.e., no
leakage), then the binary addition operators can be defined like this:
<pre>
Class operator+(Class &&lhs, Class const &rhs)
{
lhs.add(rhs);
return std::move(lhs);
}
Class operator+(Class const &lhs, Class const &rhs)
{
Class tmp(lhs);
tmp.add(rhs);
return tmp;
}
</pre>
Likewise, <em >operator+=</em> can be defined for lvalue or rvalue <em >Class</em>
objects using reference modifiers.
<p>
As binary operators can all be implemented alike, given the specific
members implementing the implied operations, these operators can very well be
provided using templates.
<p>
By inheriting from the class template <em >BinopsBase</em> classes offering such
specific functions can a particular <em >operator@=</em> then automatically also
offers the matching binary operators after including
<em >bobcat/binopsbase</em>. Since the binary function templates are not
instantiated until used their definitions can be processed by the compiler
even if a class implements only a subset of the available binary assignment
operators.
<p>
To provide a class <em >Class</em> with binary operators (and binary compound
operators) the class <em >Class</em> must implement a member <em >void swap(Class
&other)</em>, and it should implement (a subset of) the following members
(preferably in the class's private section):
<ul>
<li> <em >void mul(Class const &rhs)</em> - to provide operators <em >*</em> and <em >*=</em>
<li> <em >void div(Class const &rhs)</em> - to provide operators <em >/</em> and <em >/=</em>
<li> <em >void mod(Class const &rhs)</em> - to provide operators <em >%</em> and <em >%=</em>
<li> <em >void add(Class const &rhs)</em> - to provide operators <em >+</em> and <em >+=</em>
<li> <em >void sub(Class const &rhs)</em> - to provide operators <em >-</em> and <em >-=</em>
<li> <em >void shl(Class const &rhs)</em> - to provide operators <em ><<</em> and <em ><<=</em>
<li> <em >void shr(Class const &rhs)</em> - to provide operators <em >>></em> and <em >>>=</em>
<li> <em >void and_(Class const &rhs)</em> - to provide operators <em >&</em> and <em >&=</em>
<li> <em >void or_(Class const &rhs)</em> - to provide operators <em >|</em> and <em >|=</em>
<li> <em >void xor_(Class const &rhs)</em> - to provide operators <em >^</em> and <em >^=</em>
</ul>
Note the trailing underscore for the members <em >and_, or_</em>, and <em >xor_</em>:
the underscores are used to prevent conflicts with the <em >and, or,</em> and
<em >xor</em> keywords.
<p>
Next, <em >Class</em> should publicly inherit from
<pre>
FBB::BinopsBase<Class, int ...operators>
</pre>
where <em >int ...operators</em> lists the specific set of binary operators that
are requested. E.g., to provide <em >Class</em> with multiplication, division,
modulo, and shit-operators its class interface should start as shown:
<pre>
class Class: public FBB::BinopsBase<Class, '*', '/', '%', '<', '>'>
</pre>
There is no specific ordering required when specifying <em >int
...operators</em>. Note that <em >'<'</em> and <em >'>'</em> in the <em >int ...operators</em> list
specify, respectively, the shift-left and shift-right operators. All other
operators are specified by their common operator, specified as character
constants.
<p>
If, as advised, the members implementing the required binary operations
are declared in the class's private section then the class's interface should
declare its base class as a friend. E.g.,
<pre>
class Class: public FBB::BinopsBase<Class, '*', '/', '%', '<', '>'>
{
friend FBB::BinopsBase<Class, '*', '/', '%', '<', '>'>;
public:
...
private:
void mul(Class const &rhs);
void div(Class const &rhs);
void mod(Class const &rhs);
void shl(Class const &rhs);
void shr(Class const &rhs);
};
</pre>
<p>
<h2 >INHERITS FROM</h2>
<p>
Several Internal-use-only Bobcat classes, completing the <em >BinopsBase</em>
class template.
<p>
<h2 >OVERLOADED OPERATORS</h2>
<p>
Assuming <em >BinopsBase</em> is a base class of the class <em >Class</em>, then
for each of the requested binary operators (e.g., <em >@</em>) the following
operators are now available:
<p>
<pre>
free operators:
Class operator@(Class const &lhs, Class const &rhs);
Class operator@(Class &&lhs, Class const &rhs);
members:
Class &operator@(Class const &rhs) &;
Class &&operator@(Class const &rhs) &&;
</pre>
<p>
<h2 >EXAMPLE</h2>
<pre >
#include "../binopsbase"
#include <iostream>
using namespace std;
class Demo1: public FBB::BinopsBase<Demo1, '+', '-'>
{
friend FBB::BinopsBase<Demo1, '+', '-'>;
public:
void swap(Demo1 &other)
{}
private:
void add(Demo1 const &rhs)
{
cout << "adding two Demo1 objects\n";
}
void sub(Demo1 const &rhs)
{
cout << "subtracting two Demo1 objects\n";
}
};
class Demo2: public FBB::BinopsBase<Demo2, '+', '^'>
{
friend FBB::BinopsBase<Demo2, '+', '^'>;
public:
void swap(Demo2 &other)
{}
private:
void add(Demo2 const &rhs)
{
cout << "adding two Demo2 objects\n";
}
void xor_(Demo2 const &rhs)
{
cout << "xor-ing two Demo2 objects\n";
}
};
int main()
{
Demo1 d1a, d1b;
Demo1 d1c = d1a + d1b;
d1a += d1b;
d1c = Demo1{} + d1b;
Demo2 d2a, d2b;
Demo2 d2c = d2a + d2b;
d2a ^= d2b;
d2c = Demo2{} ^ d2b;
}
</pre>
<p>
<h2 >FILES</h2>
<em >bobcat/binopsbase</em> - defines the binary operator function templates
<p>
<h2 >SEE ALSO</h2>
<strong >bobcat/binops</strong>(3)
<strong >bobcat</strong>(7)
<p>
<h2 >BUGS</h2>
None Reported.
<p>
<h2 >DISTRIBUTION FILES</h2>
<ul>
<li> <em >bobcat_4.04.00-x.dsc</em>: detached signature;
<li> <em >bobcat_4.04.00-x.tar.gz</em>: source archive;
<li> <em >bobcat_4.04.00-x_i386.changes</em>: change log;
<li> <em >libbobcat1_4.04.00-x_*.deb</em>: debian package holding the
libraries;
<li> <em >libbobcat1-dev_4.04.00-x_*.deb</em>: debian package holding the
libraries, headers and manual pages;
<li> <em >http://sourceforge.net/projects/bobcat</em>: public archive location;
</ul>
<p>
<h2 >BOBCAT</h2>
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.
<p>
<h2 >COPYRIGHT</h2>
This is free software, distributed under the terms of the
GNU General Public License (GPL).
<p>
<h2 >AUTHOR</h2>
Frank B. Brokken (<strong >f.b.brokken@rug.nl</strong>).
<p>
|