Skip to content

Commit 95924b1

Browse files
committed
Add boost/core/string_view.hpp
1 parent 5e382ef commit 95924b1

File tree

4 files changed

+799
-0
lines changed

4 files changed

+799
-0
lines changed

doc/string_view.qbk

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
[/
2+
Copyright 2021 Peter Dimov
3+
Distributed under the Boost Software License, Version 1.0.
4+
https://boost.org/LICENSE_1_0.txt
5+
]
6+
7+
[section:string_view string_view]
8+
9+
[simplesect Authors]
10+
11+
* Peter Dimov
12+
13+
[endsimplesect]
14+
15+
[section Header <boost/core/string_view.hpp>]
16+
17+
The header `<boost/core/string_view.hpp>` defines `boost::core::string_view`,
18+
a portable and interoperable implementation of `std::string_view`.
19+
20+
Unlike `boost::string_view`, `boost::core::string_view` has implicit
21+
conversions from and to `std::string_view`, which allows Boost libraries that
22+
support C++11/C++14 to use it in interfaces without forcing users to forgo the
23+
use of `std::string_view` in their code.
24+
25+
[section Synopsis]
26+
27+
``
28+
namespace boost
29+
{
30+
namespace core
31+
{
32+
33+
template<class Ch> class basic_string_view
34+
{
35+
private:
36+
37+
Ch const* data_;
38+
std::size_t size_;
39+
40+
public:
41+
42+
// types
43+
44+
typedef std::char_traits<Ch> traits_type;
45+
typedef Ch value_type;
46+
typedef Ch* pointer;
47+
typedef Ch const* const_pointer;
48+
typedef Ch& reference;
49+
typedef Ch const& const_reference;
50+
typedef Ch const* const_iterator;
51+
typedef const_iterator iterator;
52+
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
53+
typedef const_reverse_iterator reverse_iterator;
54+
typedef std::size_t size_type;
55+
typedef std::ptrdiff_t difference_type;
56+
57+
// npos
58+
59+
static constexpr size_type npos = static_cast<size_type>( -1 );
60+
61+
public:
62+
63+
// construction and assignment
64+
65+
constexpr basic_string_view() noexcept;
66+
constexpr basic_string_view( basic_string_view const& ) noexcept = default;
67+
constexpr basic_string_view& operator=( basic_string_view const& ) noexcept & = default;
68+
constexpr basic_string_view( Ch const* str ) noexcept;
69+
constexpr basic_string_view( Ch const* str, size_type len ) noexcept;
70+
constexpr basic_string_view( Ch const* begin, Ch const* end ) noexcept;
71+
template<class A> basic_string_view(std::basic_string<Ch, std::char_traits<Ch>, A> const& str ) noexcept;
72+
basic_string_view(std::basic_string_view<Ch, std::char_traits<Ch>> const& str ) noexcept;
73+
74+
// iterator support
75+
76+
constexpr const_iterator begin() const noexcept;
77+
constexpr const_iterator end() const noexcept;
78+
constexpr const_iterator cbegin() const noexcept;
79+
constexpr const_iterator cend() const noexcept;
80+
constexpr const_reverse_iterator rbegin() const noexcept;
81+
constexpr const_reverse_iterator rend() const noexcept;
82+
constexpr const_reverse_iterator crbegin() const noexcept;
83+
constexpr const_reverse_iterator crend() const noexcept;
84+
85+
// capacity
86+
87+
constexpr size_type size() const noexcept;
88+
constexpr size_type length() const noexcept;
89+
constexpr size_type max_size() const noexcept;
90+
constexpr bool empty() const noexcept;
91+
92+
// element access
93+
94+
constexpr const_reference operator[]( size_type pos ) const noexcept;
95+
constexpr const_reference at( size_type pos ) const;
96+
constexpr const_reference front() const noexcept;
97+
constexpr const_reference back() const noexcept;
98+
constexpr const_pointer data() const noexcept;
99+
100+
// modifiers
101+
102+
constexpr void remove_prefix( size_type n ) noexcept;
103+
constexpr void remove_suffix( size_type n ) noexcept;
104+
constexpr void swap( basic_string_view& s ) noexcept;
105+
106+
// string operations
107+
108+
constexpr size_type copy( Ch* s, size_type n, size_type pos = 0 ) const;
109+
constexpr basic_string_view substr( size_type pos = 0, size_type n = npos ) const;
110+
111+
constexpr int compare( basic_string_view s ) const noexcept;
112+
constexpr int compare( size_type pos1, size_type n1, basic_string_view s ) const;
113+
constexpr int compare( size_type pos1, size_type n1, basic_string_view s, size_type pos2, size_type n2 ) const;
114+
constexpr int compare( Ch const* s ) const;
115+
constexpr int compare( size_type pos1, size_type n1, Ch const* s ) const;
116+
constexpr int compare( size_type pos1, size_type n1, Ch const* s, size_type n2 ) const;
117+
118+
constexpr bool starts_with( basic_string_view x ) const noexcept;
119+
constexpr bool starts_with( Ch x ) const noexcept;
120+
constexpr bool starts_with( Ch const* x ) const;
121+
122+
constexpr bool ends_with( basic_string_view x ) const noexcept;
123+
constexpr bool ends_with( Ch x ) const noexcept; constexpr bool ends_with( Ch const* x ) const;
124+
125+
// searching
126+
127+
constexpr size_type find( basic_string_view s, size_type pos = 0 ) const noexcept;
128+
constexpr size_type find( Ch c, size_type pos = 0 ) const noexcept;
129+
constexpr size_type find( Ch const* s, size_type pos, size_type n ) const;
130+
constexpr size_type find( Ch const* s, size_type pos = 0 ) const;
131+
132+
constexpr size_type rfind( basic_string_view s, size_type pos = npos ) const noexcept;
133+
constexpr size_type rfind( Ch c, size_type pos = npos ) const noexcept;
134+
constexpr size_type rfind( Ch const* s, size_type pos, size_type n ) const;
135+
constexpr size_type rfind( Ch const* s, size_type pos = npos ) const;
136+
137+
constexpr size_type find_first_of( basic_string_view s, size_type pos = 0 ) const noexcept;
138+
constexpr size_type find_first_of( Ch c, size_type pos = 0 ) const noexcept;
139+
constexpr size_type find_first_of( Ch const* s, size_type pos, size_type n ) const;
140+
constexpr size_type find_first_of( Ch const* s, size_type pos = 0 ) const;
141+
142+
constexpr size_type find_last_of( basic_string_view s, size_type pos = npos ) const noexcept;
143+
constexpr size_type find_last_of( Ch c, size_type pos = npos ) const noexcept;
144+
constexpr size_type find_last_of( Ch const* s, size_type pos, size_type n ) const;
145+
constexpr size_type find_last_of( Ch const* s, size_type pos = npos ) const;
146+
147+
constexpr size_type find_first_not_of( basic_string_view s, size_type pos = 0 ) const noexcept;
148+
constexpr size_type find_first_not_of( Ch c, size_type pos = 0 ) const noexcept;
149+
constexpr size_type find_first_not_of( Ch const* s, size_type pos, size_type n ) const;
150+
constexpr size_type find_first_not_of( Ch const* s, size_type pos = 0 ) const;
151+
152+
constexpr size_type find_last_not_of( basic_string_view s, size_type pos = npos ) const noexcept;
153+
constexpr size_type find_last_not_of( Ch c, size_type pos = npos ) const noexcept;
154+
constexpr size_type find_last_not_of( Ch const* s, size_type pos, size_type n ) const;
155+
constexpr size_type find_last_not_of( Ch const* s, size_type pos = npos ) const;};
156+
157+
typedef basic_string_view<char> string_view;
158+
typedef basic_string_view<wchar_t> wstring_view;
159+
typedef basic_string_view<char16_t> u16string_view;
160+
typedef basic_string_view<char32_t> u32string_view;
161+
typedef basic_string_view<char8_t> u8string_view;
162+
163+
} // namespace core
164+
} // namespace boost
165+
``
166+
167+
[endsect]
168+
169+
[section Construction]
170+
171+
[section constexpr basic_string_view() noexcept;]
172+
173+
* *Ensures:* `data() == 0`, `size() == 0`.
174+
175+
[endsect]
176+
177+
[endsect]
178+
179+
[endsect]
180+
181+
[endsect]

0 commit comments

Comments
 (0)