- メインページ
- モジュール
- ネームスペース
- データ構造
- ファイル

- ファイル一覧
- グローバル

operators.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28
33 #ifndef __INCLUDE_MIST_OPERATORS__
34 #define __INCLUDE_MIST_OPERATORS__
35
36 #include "../config/mist_conf.h"
37
38
39 // mist名前空間の始まり
40 _MIST_BEGIN
41
49
50
51
71 template < class T >
72 struct implement_operator_add
73 {
74 friend T operator +( const T &obj1, const T &obj2 )
75 {
76 T obj( obj1 );
77 obj += obj2;
78 return( obj );
79 }
80 };
81
82
102 template < class T >
103 struct implement_operator_sub
104 {
105 friend T operator -( const T &obj1, const T &obj2 )
106 {
107 T obj( obj1 );
108 obj -= obj2;
109 return( obj );
110 }
111 };
112
113
114
134 template < class T >
135 struct implement_operator_mul
136 {
137 friend T operator *( const T &obj1, const T &obj2 )
138 {
139 T obj( obj1 );
140 obj *= obj2;
141 return( obj );
142 }
143 };
144
145
146
166 template < class T >
167 struct implement_operator_div
168 {
169 friend T operator /( const T &obj1, const T &obj2 )
170 {
171 T obj( obj1 );
172 obj /= obj2;
173 return( obj );
174 }
175 };
176
177
178
198 template < class T >
199 struct implement_operator_ne
200 {
201 friend bool operator !=( const T &obj1, const T &obj2 )
202 {
203 return( !( obj1 == obj2 ) );
204 }
205 };
206
207
208
228 template < class T >
229 struct implement_operator_gt
230 {
231 friend bool operator >( const T &obj1, const T &obj2 )
232 {
233 return( obj2 < obj1 );
234 }
235 };
236
237
238
258 template < class T >
259 struct implement_operator_le
260 {
261 friend bool operator <=( const T &obj1, const T &obj2 )
262 {
263 return( !( obj2 < obj1 ) );
264 }
265 };
266
267
268
288 template < class T >
289 struct implement_operator_ge
290 {
291 friend bool operator >=( const T &obj1, const T &obj2 )
292 {
293 return( !( obj1 < obj2 ) );
294 }
295 };
296
297
298
318 template < class T >
319 struct implement_operator_mod
320 {
321 friend T operator %( const T &obj1, const T &obj2 )
322 {
323 T obj( obj1 );
324 obj %= obj2;
325 return( obj );
326 }
327 };
328
329
330
350 template < class T >
351 struct implement_operator_or
352 {
353 friend T operator |( const T &obj1, const T &obj2 )
354 {
355 T obj( obj1 );
356 obj |= obj2;
357 return( obj );
358 }
359 };
360
361
362
382 template < class T >
383 struct implement_operator_and
384 {
385 friend T operator &( const T &obj1, const T &obj2 )
386 {
387 T obj( obj1 );
388 obj &= obj2;
389 return( obj );
390 }
391 };
392
393
394
414 template < class T >
415 struct implement_operator_xor
416 {
417 friend T operator ^( const T &obj1, const T &obj2 )
418 {
419 T obj( obj1 );
420 obj ^= obj2;
421 return( obj );
422 }
423 };
424
425
426
433 template < class T >
434 struct implement_arithmetic_operators : public
435 implement_operator_add< T >,
436 implement_operator_sub< T >,
437 implement_operator_mul< T >,
438 implement_operator_div< T >
439 {
440 };
441
442
443
450 template < class T >
451 struct implement_comparison_operators : public
452 implement_operator_ne < T >,
453 implement_operator_gt < T >,
454 implement_operator_le < T >,
455 implement_operator_ge < T >
456 {
457 };
458
459
460
461
468 template < class T >
469 struct implement_bit_operators : public
470 implement_operator_or< T >,
471 implement_operator_and< T >,
472 implement_operator_xor< T >
473 {
474 };
475
476
477
485 template < class T >
486 struct implement_operators : public
487 implement_arithmetic_operators< T >,
488 implement_comparison_operators< T >,
489 implement_operator_mod< T >,
490 implement_bit_operators< T >
491 {
492 };
493
494
496 // 演算子の実装補助グループの終わり
497
498
499 // mist名前空間の終わり
500 _MIST_END
501
502
503 #endif // __INCLUDE_MIST_OPERATORS__
504