string_view.h
Go to the documentation of this file.
1
2/************************************************************************************
3* *
4* Copyright (c) 2014 - 2018 Axel Menzel <info@rttr.org> *
5* *
6* This file is part of RTTR (Run Time Type Reflection) *
7* License: MIT License *
8* *
9* Permission is hereby granted, free of charge, to any person obtaining *
10* a copy of this software and associated documentation files (the "Software"), *
11* to deal in the Software without restriction, including without limitation *
12* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
13* and/or sell copies of the Software, and to permit persons to whom the *
14* Software is furnished to do so, subject to the following conditions: *
15* *
16* The above copyright notice and this permission notice shall be included in *
17* all copies or substantial portions of the Software. *
18* *
19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
20* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
21* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
22* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
23* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
24* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
25* SOFTWARE. *
26* *
27*************************************************************************************/
28
29#ifndef RTTR_STRING_VIEW_H_
30#define RTTR_STRING_VIEW_H_
31
32#include "rttr/detail/base/core_prerequisites.h"
33
34#include <string>
35#include <ostream>
36
37namespace rttr
38{
39
47template<typename CharT, typename Traits = std::char_traits<CharT> >
49{
50 public:
53 using pointer = CharT*;
54 using const_pointer = const CharT*;
55 using reference = CharT&;
56 using const_reference = const CharT&;
59 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
61 using size_type = std::size_t;
62 using difference_type = std::ptrdiff_t;
64
69
74
82
90
97
103
110
117
125
133
141
149
158
167
174
181
188
195
203
210
217
228
234
240
241
249
257
267
276
277 private:
278 const value_type* m_data;
279 size_type m_size;
280};
281
285// friend functions
286// MSVC 2013 cannot handle type deduction correctly, thats why we have to declare and
287// define all possibility compares explicitly
288
299
303
306 const char* rhs) RTTR_NOEXCEPT;
307
311
315
317
328
332
335 const char* rhs) RTTR_NOEXCEPT;
336
340
344
346
357
361
364 const char* rhs) RTTR_NOEXCEPT;
365
369
373
375
386
390
393 const char* rhs) RTTR_NOEXCEPT;
394
398
402
404
415
419
422 const char* rhs) RTTR_NOEXCEPT;
423
427
431
433
444
448
451 const char* rhs) RTTR_NOEXCEPT;
452
456
460
462
466
470
474
478
480
489
494
495
496} // end namespace rttr
497
498#include "rttr/detail/impl/string_view_impl.h"
499
500#endif // RTTR_STRING_VIEW_H_
The array_range class provides a view into an underlying data structure with lower and upper limits.
Definition array_range.h:64
The class template basic_string_view describes an non-owning reference to a constant contiguous seque...
Definition string_view.h:49
constexpr const_reference back() const
Returns reference to the last character in the view.
constexpr void remove_suffix(size_type n) noexcept
Moves the end of the view back by n characters.
constexpr const_iterator cbegin() const noexcept
Returns an iterator to the beginning of the view.
const_pointer const_iterator
Definition string_view.h:57
constexpr int compare(basic_string_view v) const noexcept
The function compares the two views by calling Traits::compare(data(), v.data(), length),...
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition string_view.h:59
const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first character of the reversed view.
constexpr const_iterator end() const noexcept
Returns an iterator to the character following the last character of the view.
constexpr basic_string_view() noexcept
Default constructor.
std::size_t size_type
Definition string_view.h:61
CharT value_type
Definition string_view.h:52
constexpr const_iterator begin() const noexcept
Returns an iterator to the beginning of the view.
constexpr size_type length() const noexcept
Returns the number of CharT elements in the view, i.e.
const_reverse_iterator reverse_iterator
Definition string_view.h:60
std::basic_string< CharT, Traits > to_string(const Allocator &a=Allocator()) const
Creates a basic_string with a copy of the content of the current view.
constexpr size_type max_size() const noexcept
The largest possible number of char-like objects that can be referred to by a basic_string_view.
const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the character following the last character of the reversed view.
constexpr const_iterator cend() const noexcept
Returns an iterator to the character following the last character of the view.
const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the character following the last character of the reversed view.
const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first character of the reversed view.
std::ptrdiff_t difference_type
Definition string_view.h:62
constexpr const_pointer data() const noexcept
Returns a pointer to the underlying character array.
constexpr const_reference front() const
Returns reference to the first character in the view.
constexpr bool empty() const noexcept
Checks if the view has no characters, i.e.
const CharT * const_pointer
Definition string_view.h:54
static size_type npos
Definition string_view.h:63
constexpr size_type size() const noexcept
Returns the number of CharT elements in the view, i.e.
constexpr void swap(basic_string_view &s) noexcept
constexpr void remove_prefix(size_type n) noexcept
Moves the start of the view forward by n characters.
Definition access_levels.h:34