ReactOS 0.4.16-dev-109-gf4cb10f
_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
27template <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
44template <class _CharT, class _Traits, class _Alloc>
46operator+(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
62template <class _CharT, class _Traits, class _Alloc>
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
78template <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
96template <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
117template <class _CharT, class _Traits, class _Alloc>
118inline _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
136template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
137inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
145 _STLP_PRIV __on_right>(__lhs, __rhs);
146}
147
148template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
149inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
157 _STLP_PRIV __on_left>(__lhs, __rhs);
158}
159
160// addition with C string
161template <class _CharT, class _Traits, class _Alloc>
162inline _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
180template <class _CharT, class _Traits, class _Alloc>
181inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
183 _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
188operator+(const _CharT* __s,
190 const size_t __n = _Traits::length(__s);
193 _STLP_PRIV __on_right> __root_type;
196 __root_type,
198}
199
200template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
201inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
206 const _CharT* __s) {
207 const size_t __n = _Traits::length(__s);
211}
212
213template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
214inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
218operator+(const _CharT* __s,
220 const size_t __n = _Traits::length(__s);
224}
225
226// addition with char
227template <class _CharT, class _Traits, class _Alloc>
228inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
230 _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
235operator+(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
244template <class _CharT, class _Traits, class _Alloc>
245inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
247 _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
252operator+(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
261template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
262inline _STLP_PRIV __bstr_sum<_CharT, _Traits, _Alloc,
269}
270
271template <class _CharT, class _Traits, class _Alloc, class _Left, class _Right, class _StorageDir>
279}
280
281#endif /* _STLP_USE_TEMPLATE_EXPRESSION */
282
283// Operator== and operator!=
284
285template <class _CharT, class _Traits, class _Alloc>
286inline 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)
293template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
294inline bool _STLP_CALL
297 return __x.size() == __y.size() && _Traits::compare(__x.data(), __y.data(), __x.size()) == 0;
298}
299
300template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
301inline 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
309template <class _CharT, class _Traits, class _Alloc>
310inline bool _STLP_CALL
311operator==(const _CharT* __s,
314 size_t __n = _Traits::length(__s);
315 return __n == __y.size() && _Traits::compare(__s, __y.data(), __n) == 0;
316}
317
318template <class _CharT, class _Traits, class _Alloc>
319inline 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)
328template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
329inline bool _STLP_CALL
330operator==(const _CharT* __s,
333 size_t __n = _Traits::length(__s);
334 return __n == __y.size() && _Traits::compare(__s, __y.data(), __n) == 0;
335}
336
337template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
338inline 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
349template <class _CharT, class _Traits, class _Alloc>
350inline bool _STLP_CALL
354 __y.begin(), __y.end()) < 0;
355}
356
357#if defined (_STLP_USE_TEMPLATE_EXPRESSION)
358template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
359inline bool _STLP_CALL
362 return basic_string<_CharT,_Traits,_Alloc> ::_M_compare(__x.begin(), __x.end(),
363 __y.begin(), __y.end()) < 0;
364}
365
366template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
367inline bool _STLP_CALL
371 __y.begin(), __y.end()) < 0;
372}
373#endif /* _STLP_USE_TEMPLATE_EXPRESSION */
374
375template <class _CharT, class _Traits, class _Alloc>
376inline bool _STLP_CALL
377operator<(const _CharT* __s,
380 size_t __n = _Traits::length(__s);
382 __y.begin(), __y.end()) < 0;
383}
384
385template <class _CharT, class _Traits, class _Alloc>
386inline 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)
396template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
397inline bool _STLP_CALL
398operator<(const _CharT* __s,
401 size_t __n = _Traits::length(__s);
403 __y.begin(), __y.end()) < 0;
404}
405
406template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
407inline 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 */
423template <class _CharT, class _Traits, class _Alloc>
424inline bool _STLP_CALL
427{ return !(__x == __y); }
428
429template <class _CharT, class _Traits, class _Alloc>
430inline bool _STLP_CALL
433{ return __y < __x; }
434
435template <class _CharT, class _Traits, class _Alloc>
436inline bool _STLP_CALL
439{ return !(__y < __x); }
440
441template <class _CharT, class _Traits, class _Alloc>
442inline bool _STLP_CALL
445{ return !(__x < __y); }
446
447# if defined (_STLP_USE_TEMPLATE_EXPRESSION)
448template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
449inline bool _STLP_CALL
452{ return !(__x==__y); }
453
454template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
455inline bool _STLP_CALL
458{ return !(__x==__y); }
459# endif
460
461#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
462
463template <class _CharT, class _Traits, class _Alloc>
464inline bool _STLP_CALL
465operator!=(const _CharT* __s,
468 return !(__s == __y);
469}
470
471template <class _CharT, class _Traits, class _Alloc>
472inline bool _STLP_CALL
474 const _CharT* __s) {
476 return !(__x == __s);
477}
478
479#if defined (_STLP_USE_TEMPLATE_EXPRESSION)
480template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
481inline bool _STLP_CALL
482operator!=(const _CharT* __s,
485 return !(__s == __y);
486}
487
488template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
489inline bool _STLP_CALL
491 const _CharT* __s) {
493 return !(__x == __s);
494}
495#endif /* _STLP_USE_TEMPLATE_EXPRESSION */
496
497template <class _CharT, class _Traits, class _Alloc>
498inline bool _STLP_CALL
499operator>(const _CharT* __s,
502 return __y < __s;
503}
504
505template <class _CharT, class _Traits, class _Alloc>
506inline bool _STLP_CALL
508 const _CharT* __s) {
510 return __s < __x;
511}
512
513#if defined (_STLP_USE_TEMPLATE_EXPRESSION)
514template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
515inline bool _STLP_CALL
516operator>(const _CharT* __s,
519 return __y < __s;
520}
521
522template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
523inline bool _STLP_CALL
525 const _CharT* __s) {
527 return __s < __x;
528}
529#endif /* _STLP_USE_TEMPLATE_EXPRESSION */
530
531template <class _CharT, class _Traits, class _Alloc>
532inline bool _STLP_CALL
533operator<=(const _CharT* __s,
536 return !(__y < __s);
537}
538
539template <class _CharT, class _Traits, class _Alloc>
540inline bool _STLP_CALL
542 const _CharT* __s) {
544 return !(__s < __x);
545}
546
547#if defined (_STLP_USE_TEMPLATE_EXPRESSION)
548template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
549inline bool _STLP_CALL
550operator<=(const _CharT* __s,
553 return !(__y < __s);
554}
555
556template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
557inline bool _STLP_CALL
559 const _CharT* __s) {
561 return !(__s < __x);
562}
563#endif /* _STLP_USE_TEMPLATE_EXPRESSION */
564
565template <class _CharT, class _Traits, class _Alloc>
566inline bool _STLP_CALL
567operator>=(const _CharT* __s,
570 return !(__s < __y);
571}
572
573template <class _CharT, class _Traits, class _Alloc>
574inline bool _STLP_CALL
576 const _CharT* __s) {
578 return !(__x < __s);
579}
580
581#if defined (_STLP_USE_TEMPLATE_EXPRESSION)
582template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
583inline bool _STLP_CALL
584operator>=(const _CharT* __s,
587 return !(__s < __y);
588}
589
590template <class _CharT, class _Traits, class _Alloc, class _Lhs, class _Rhs, class _StoreDir>
591inline 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
return __n
Definition: _algo.h:75
#define _STLP_CALL
Definition: _bc.h:131
#define _Alloc
Definition: _bvector.h:330
#define _STLP_PRIV
Definition: _dm.h:70
_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)
bool _STLP_CALL operator>(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
bool _STLP_CALL operator!=(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
bool _STLP_CALL operator<(const basic_string< _CharT, _Traits, _Alloc > &__x, const basic_string< _CharT, _Traits, _Alloc > &__y)
bool _STLP_CALL operator==(const basic_string< _CharT, _Traits, _Alloc > &__x, const basic_string< _CharT, _Traits, _Alloc > &__y)
bool _STLP_CALL operator>=(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
bool _STLP_CALL operator<=(const _CharT *__s, const basic_string< _CharT, _Traits, _Alloc > &__y)
iterator end()
Definition: _string.h:386
size_type size() const
Definition: _string.h:400
allocator_type get_allocator() const
Definition: _string.h:154
const _CharT * data() const
Definition: _string.h:950
iterator begin()
Definition: _string.h:385
#define _STLP_FIX_LITERAL_BUG(__x)
Definition: features.h:301
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define __c
Definition: schilyio.h:209