ReactOS  0.4.14-dev-114-gc8cbd56
_string_operators.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003
3  * Francois Dumont
4  *
5  * This material is provided "as is", with absolutely no warranty expressed
6  * or implied. Any use is at your own risk.
7  *
8  * Permission to use or copy this software for any purpose is hereby granted
9  * without fee, provided the above notices are retained on all copies.
10  * Permission to modify the code and to distribute modified code is granted,
11  * provided the above notices are retained, and a notice that the code was
12  * modified is included with the above copyright notice.
13  *
14  */
15 
16 #ifndef _STLP_STRING_OPERATORS_H
17 #define _STLP_STRING_OPERATORS_H
18 
20 
21 #if !defined (_STLP_USE_TEMPLATE_EXPRESSION)
22 
23 # if defined (__GNUC__) || defined (__MLCCPP__)
24 # define _STLP_INIT_AMBIGUITY 1
25 # endif
26 
27 template <class _CharT, class _Traits, class _Alloc>
32  typedef typename _Str::_Reserve_t _Reserve_t;
33 # if defined (_STLP_INIT_AMBIGUITY)
34  // gcc counts this as a function
35  _Str __result = _Str(_Reserve_t(), __s.size() + __y.size(), __s.get_allocator());
36 # else
37  _Str __result(_Reserve_t(), __s.size() + __y.size(), __s.get_allocator());
38 # endif
39  __result.append(__s);
40  __result.append(__y);
41  return __result;
42 }
43 
44 template <class _CharT, class _Traits, class _Alloc>
46 operator+(const _CharT* __s,
50  typedef typename _Str::_Reserve_t _Reserve_t;
51  const size_t __n = _Traits::length(__s);
52 # if defined (_STLP_INIT_AMBIGUITY)
53  _Str __result = _Str(_Reserve_t(), __n + __y.size(), __y.get_allocator());
54 # else
55  _Str __result(_Reserve_t(), __n + __y.size(), __y.get_allocator());
56 # endif
57  __result.append(__s, __s + __n);
58  __result.append(__y);
59  return __result;
60 }
61 
62 template <class _CharT, class _Traits, class _Alloc>
64 operator+(_CharT __c,
67  typedef typename _Str::_Reserve_t _Reserve_t;
68 # if defined (_STLP_INIT_AMBIGUITY)
69  _Str __result = _Str(_Reserve_t(), 1 + __y.size(), __y.get_allocator());
70 # else
71  _Str __result(_Reserve_t(), 1 + __y.size(), __y.get_allocator());
72 # endif
73  __result.push_back(__c);
74  __result.append(__y);
75  return __result;
76 }
77 
78 template <class _CharT, class _Traits, class _Alloc>
81  const _CharT* __s) {
84  typedef typename _Str::_Reserve_t _Reserve_t;
85  const size_t __n = _Traits::length(__s);
86 # if defined (_STLP_INIT_AMBIGUITY)
87  _Str __result = _Str(_Reserve_t(), __x.size() + __n, __x.get_allocator());
88 # else
89  _Str __result(_Reserve_t(), __x.size() + __n, __x.get_allocator());
90 # endif
91  __result.append(__x);
92  __result.append(__s, __s + __n);
93  return __result;
94 }
95 
96 template <class _CharT, class _Traits, class _Alloc>
99  const _CharT __c) {
101  typedef typename _Str::_Reserve_t _Reserve_t;
102 # if defined (_STLP_INIT_AMBIGUITY)
103  _Str __result = _Str(_Reserve_t(), __x.size() + 1, __x.get_allocator());
104 # else
105  _Str __result(_Reserve_t(), __x.size() + 1, __x.get_allocator());
106 # endif
107  __result.append(__x);
108  __result.push_back(__c);
109  return __result;
110 }
111 
112 # undef _STLP_INIT_AMBIGUITY
113 
114 #else /* _STLP_USE_TEMPLATE_EXPRESSION */
115 
116 // addition with basic_string
117 template <class _CharT, class _Traits, class _Alloc>
118 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
120  _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
129  _STLP_PRIV __on_right> __root_type;
130  __root_type __root(__rhs, _STLP_PRIV __sum_storage_elem<_CharT, _Traits, _Alloc>(__lhs.get_allocator()));
132  __root_type,
133  _STLP_PRIV __on_right>(__lhs, __root);
134 }
135 
136 template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
137 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
145  _STLP_PRIV __on_right>(__lhs, __rhs);
146 }
147 
148 template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
149 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
157  _STLP_PRIV __on_left>(__lhs, __rhs);
158 }
159 
160 // addition with C string
161 template <class _CharT, class _Traits, class _Alloc>
162 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
164  _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
170  const _CharT* __s) {
171  const size_t __n = _Traits::length(__s);
174  _STLP_PRIV __on_right> __root_type;
177  __root_type, _STLP_PRIV __on_right>(__x, __root);
178 }
179 
180 template <class _CharT, class _Traits, class _Alloc>
181 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
183  _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
188 operator+(const _CharT* __s,
190  const size_t __n = _Traits::length(__s);
193  _STLP_PRIV __on_right> __root_type;
196  __root_type,
198 }
199 
200 template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
201 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
206  const _CharT* __s) {
207  const size_t __n = _Traits::length(__s);
211 }
212 
213 template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
214 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
218 operator+(const _CharT* __s,
220  const size_t __n = _Traits::length(__s);
224 }
225 
226 // addition with char
227 template <class _CharT, class _Traits, class _Alloc>
228 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
230  _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
235 operator+(const basic_string<_CharT,_Traits,_Alloc>& __x, const _CharT __c) {
238  _STLP_PRIV __on_right> __root_type;
241  __root_type, _STLP_PRIV __on_right>(__x, __root);
242 }
243 
244 template <class _CharT, class _Traits, class _Alloc>
245 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
247  _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
252 operator+(const _CharT __c, const basic_string<_CharT,_Traits,_Alloc>& __x) {
255  _STLP_PRIV __on_right> __root_type;
258  __root_type, _STLP_PRIV __on_right>(__c, __root);
259 }
260 
261 template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
262 inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
269 }
270 
271 template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
278  _STLP_PRIV __on_right>(__c, __x);
279 }
280 
281 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
282 
283 // Operator== and operator!=
284 
285 template <class _CharT, class _Traits, class _Alloc>
286 inline bool _STLP_CALL
289  return __x.size() == __y.size() && _Traits::compare(__x.data(), __y.data(), __x.size()) == 0;
290 }
291 
292 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
293 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
294 inline bool _STLP_CALL
297  return __x.size() == __y.size() && _Traits::compare(__x.data(), __y.data(), __x.size()) == 0;
298 }
299 
300 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
301 inline bool _STLP_CALL
304  return __x.size() == __y.size() && _Traits::compare(__x.data(), __y.data(), __x.size()) == 0;
305 }
306 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
307 
308 
309 template <class _CharT, class _Traits, class _Alloc>
310 inline bool _STLP_CALL
311 operator==(const _CharT* __s,
314  size_t __n = _Traits::length(__s);
315  return __n == __y.size() && _Traits::compare(__s, __y.data(), __n) == 0;
316 }
317 
318 template <class _CharT, class _Traits, class _Alloc>
319 inline bool _STLP_CALL
321  const _CharT* __s) {
323  size_t __n = _Traits::length(__s);
324  return __x.size() == __n && _Traits::compare(__x.data(), __s, __n) == 0;
325 }
326 
327 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
328 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
329 inline bool _STLP_CALL
330 operator==(const _CharT* __s,
333  size_t __n = _Traits::length(__s);
334  return __n == __y.size() && _Traits::compare(__s, __y.data(), __n) == 0;
335 }
336 
337 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
338 inline bool _STLP_CALL
340  const _CharT* __s) {
342  size_t __n = _Traits::length(__s);
343  return __x.size() == __n && _Traits::compare(__x.data(), __s, __n) == 0;
344 }
345 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
346 
347 // Operator< (and also >, <=, and >=).
348 
349 template <class _CharT, class _Traits, class _Alloc>
350 inline bool _STLP_CALL
354  __y.begin(), __y.end()) < 0;
355 }
356 
357 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
358 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
359 inline bool _STLP_CALL
362  return basic_string<_CharT,_Traits,_Alloc> ::_M_compare(__x.begin(), __x.end(),
363  __y.begin(), __y.end()) < 0;
364 }
365 
366 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
367 inline bool _STLP_CALL
371  __y.begin(), __y.end()) < 0;
372 }
373 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
374 
375 template <class _CharT, class _Traits, class _Alloc>
376 inline bool _STLP_CALL
377 operator<(const _CharT* __s,
380  size_t __n = _Traits::length(__s);
382  __y.begin(), __y.end()) < 0;
383 }
384 
385 template <class _CharT, class _Traits, class _Alloc>
386 inline bool _STLP_CALL
388  const _CharT* __s) {
390  size_t __n = _Traits::length(__s);
392  __s, __s + __n) < 0;
393 }
394 
395 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
396 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
397 inline bool _STLP_CALL
398 operator<(const _CharT* __s,
401  size_t __n = _Traits::length(__s);
403  __y.begin(), __y.end()) < 0;
404 }
405 
406 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
407 inline bool _STLP_CALL
409  const _CharT* __s) {
411  size_t __n = _Traits::length(__s);
412  return basic_string<_CharT,_Traits,_Alloc> ::_M_compare(__x.begin(), __x.end(),
413  __s, __s + __n) < 0;
414 }
415 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
416 
417 #if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
418 
419 /* Only defined if _STLP_USE_SEPARATE_RELOPS_NAMESPACE is defined otherwise
420  * it might introduce ambiguity with pure template relational operators
421  * from rel_ops namespace.
422  */
423 template <class _CharT, class _Traits, class _Alloc>
424 inline bool _STLP_CALL
427 { return !(__x == __y); }
428 
429 template <class _CharT, class _Traits, class _Alloc>
430 inline bool _STLP_CALL
433 { return __y < __x; }
434 
435 template <class _CharT, class _Traits, class _Alloc>
436 inline bool _STLP_CALL
439 { return !(__y < __x); }
440 
441 template <class _CharT, class _Traits, class _Alloc>
442 inline bool _STLP_CALL
445 { return !(__x < __y); }
446 
447 # if defined (_STLP_USE_TEMPLATE_EXPRESSION)
448 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
449 inline bool _STLP_CALL
452 { return !(__x==__y); }
453 
454 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
455 inline bool _STLP_CALL
458 { return !(__x==__y); }
459 # endif
460 
461 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
462 
463 template <class _CharT, class _Traits, class _Alloc>
464 inline bool _STLP_CALL
465 operator!=(const _CharT* __s,
468  return !(__s == __y);
469 }
470 
471 template <class _CharT, class _Traits, class _Alloc>
472 inline bool _STLP_CALL
474  const _CharT* __s) {
476  return !(__x == __s);
477 }
478 
479 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
480 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
481 inline bool _STLP_CALL
482 operator!=(const _CharT* __s,
485  return !(__s == __y);
486 }
487 
488 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
489 inline bool _STLP_CALL
491  const _CharT* __s) {
493  return !(__x == __s);
494 }
495 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
496 
497 template <class _CharT, class _Traits, class _Alloc>
498 inline bool _STLP_CALL
499 operator>(const _CharT* __s,
502  return __y < __s;
503 }
504 
505 template <class _CharT, class _Traits, class _Alloc>
506 inline bool _STLP_CALL
508  const _CharT* __s) {
510  return __s < __x;
511 }
512 
513 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
514 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
515 inline bool _STLP_CALL
516 operator>(const _CharT* __s,
519  return __y < __s;
520 }
521 
522 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
523 inline bool _STLP_CALL
525  const _CharT* __s) {
527  return __s < __x;
528 }
529 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
530 
531 template <class _CharT, class _Traits, class _Alloc>
532 inline bool _STLP_CALL
533 operator<=(const _CharT* __s,
536  return !(__y < __s);
537 }
538 
539 template <class _CharT, class _Traits, class _Alloc>
540 inline bool _STLP_CALL
542  const _CharT* __s) {
544  return !(__s < __x);
545 }
546 
547 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
548 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
549 inline bool _STLP_CALL
550 operator<=(const _CharT* __s,
553  return !(__y < __s);
554 }
555 
556 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
557 inline bool _STLP_CALL
559  const _CharT* __s) {
561  return !(__s < __x);
562 }
563 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
564 
565 template <class _CharT, class _Traits, class _Alloc>
566 inline bool _STLP_CALL
567 operator>=(const _CharT* __s,
570  return !(__s < __y);
571 }
572 
573 template <class _CharT, class _Traits, class _Alloc>
574 inline bool _STLP_CALL
576  const _CharT* __s) {
578  return !(__x < __s);
579 }
580 
581 #if defined (_STLP_USE_TEMPLATE_EXPRESSION)
582 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
583 inline bool _STLP_CALL
584 operator>=(const _CharT* __s,
587  return !(__s < __y);
588 }
589 
590 template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
591 inline bool _STLP_CALL
593  const _CharT* __s) {
595  return !(__x < __s);
596 }
597 #endif /* _STLP_USE_TEMPLATE_EXPRESSION */
598 
600 
601 #endif /* _STLP_STRING_OPERATORS_H */
602 
bool _STLP_CALL operator>(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
return __n
Definition: _algo.h:75
#define _Alloc
Definition: _bvector.h:330
bool _STLP_CALL operator!=(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
static int _STLP_CALL _M_compare(const _CharT *__f1, const _CharT *__l1, const _CharT *__f2, const _CharT *__l2)
Definition: _string.h:1071
iterator begin()
Definition: _string.h:385
const _CharT * data() const
Definition: _string.h:950
_STLP_BEGIN_NAMESPACE basic_string< _CharT, _Traits, _Alloc > _STLP_CALL operator+(const basic_string< _CharT, _Traits, _Alloc > &__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
allocator_type get_allocator() const
Definition: _string.h:154
#define __c
Definition: schilyio.h:209
bool _STLP_CALL operator<(const basic_string< _CharT, _Traits, _Alloc > &__x, const basic_string< _CharT, _Traits, _Alloc > &__y)
size_type size() const
Definition: _string.h:400
iterator end()
Definition: _string.h:386
bool _STLP_CALL operator==(const basic_string< _CharT, _Traits, _Alloc > &__x, const basic_string< _CharT, _Traits, _Alloc > &__y)
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
bool _STLP_CALL operator>=(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
_Self & append(const _CharT *__first, const _CharT *__last)
Definition: _string.h:509
void push_back(_CharT __c)
Definition: _string.h:534
#define _STLP_PRIV
Definition: _dm.h:70
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_FIX_LITERAL_BUG(__x)
Definition: features.h:301
#define compare
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
bool _STLP_CALL operator<=(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
#define _STLP_CALL
Definition: _bc.h:131