-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgl_string_view.hpp
91 lines (78 loc) · 1.93 KB
/
vgl_string_view.hpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef VGL_STRING_VIEW_HPP
#define VGL_STRING_VIEW_HPP
#include "vgl_string.hpp"
namespace vgl
{
/// Templated string_view replacement.
class string_view : public detail::string_data<const char>
{
private:
/// Base class type.
using base_type = detail::string_data<const char>;
public:
/// Constructor.
constexpr explicit string_view() noexcept = default;
/// Constructor.
///
/// Intentionally not explicit.
///
/// \param op C string input.
constexpr string_view(const char* op) :
base_type(op, detail::internal_strlen(op))
{
}
/// Constructor.
///
/// \param ptr C string input.
/// \param len Length of input.
constexpr explicit string_view(const char* ptr, unsigned len) :
base_type(ptr, len)
{
}
/// Constructor.
///
/// Intentionally not explicit.
///
/// \param op C string input.
constexpr string_view(const string& op) noexcept :
base_type(op.data(), op.length())
{
}
/// Copy constructor.
///
/// \param other Source object.
constexpr string_view(const string_view& other) noexcept :
base_type(other.data(), other.length())
{
}
/// Move constructor.
///
/// \param other Source object.
constexpr string_view(string_view&& other) noexcept :
base_type(other.m_data, other.m_length)
{
}
public:
/// Assignment operator.
///
/// \param op Input data.
/// \return This object.
constexpr string_view& operator=(const string_view& op) noexcept
{
base_type::m_data = op.m_data;
base_type::m_length = op.m_length;
return *this;
}
/// Move operator.
///
/// \param op Source object.
/// \return This object.
constexpr string_view& operator=(string_view&& op) noexcept
{
base_type::m_data = op.m_data;
base_type::m_length = op.m_length;
return *this;
}
};
}
#endif