File: stringview.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (67 lines) | stat: -rw-r--r-- 2,662 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
In addition to the class tt(std::string) the class tt(std::string_view) can be
used as a wrapper-class of tt(char) arrays.  The class tt(string_view) can
be considered a light-weight tt(string) class.  Before using
tt(std::string_view) objects the tthi(string_view) header file must have been
included.

In addition to the standard constructors (default, copy, move) it offers the
following constructors:
    itemization(
    itt(constexpr string_view(char const *src, size_t nChars)), constructs a
tt(string_view) object from the first tt(nChars) characters of tt(src). The
characters in the range rangett(src, src + nChars) may be 0-valued
characters;

    itt(constexpr string_view(char const *src)), constructs a tt(string_view)
object from the NTBS starting at tt(src). The argument passed to this
constructor may not be a null pointer;

    itt(constexpr string_view(Iterator begin, Iterator end)), constructs a
tt(string_view) object from the characters in the iterator-range
rangett(begin, end).
    )
    A tt(string_view) object does not contain its own copy of the initialized
data. Instead, it refers to the characters that were used when it was
initially constructed. E.g., the following program produces unpredictable
output, but when the tt(hello) array is defined as a static array it shows
em(hello): 
    verb(    #include <string_view>
    #include <iostream>
    using namespace std;
    
    string_view fun()
    {
        char hello[] = "hello";
        return { hello };
    }
    
    int main()
    {
        string_view obj = fun();
        cout << obj << '\n';
    })

The tt(std::string_view) class provides the same members as tt(std::string),
except for members extending the tt(string_view's) characters (neither
appending nor inserting characters is possible). However, tt(string_view)
objects em(can) modify their characters (using the index operator or tt(at)
member).

The tt(string_view) class also offers some extra members:
    itemization(
    ithtq(remove_prefix)(remove_prefix(size_t step))
       (moves the begin of the object's character range forward by tt(step)
        positions.)
    ithtq(remove_suffix)(remove_suffix(size_t step))
       (moves the end of the object's character range backward by tt(step)
        positions.)
    ithtq(operator""sv)(constexpr string_view operator""sv(char const *str,
        size_t len))
       (returns a tt(string_view) object containing tt(len) characters of
        tt(str).)
    )

Like tt(std::string) the tt(std::string_view) class provides hashing
facilities, so tt(string_view) objects can be used as keys in, e.g., tt(map)
containers (cf. chapter ref(CONTAINERS)).