std::string like compile-time const char* string
$begingroup$
I want to write a very simple std::string like compile-time const char* string.
I need to work with strings in the compiletime, just like with strings, I implemented basic functions.
class cstring final {
const char* str_;
std::size_t size_;
public:
constexpr cstring(const char* str, std::size_t size, std::size_t prefix = 0, std::size_t suffix = 0) noexcept
: str_{str + prefix},
size_{size - prefix - suffix} {}
template <std::size_t N>
constexpr cstring(const char (&str)[N]) noexcept : cstring{str, N - 1, 0, 0} {}
constexpr cstring() noexcept : cstring{nullptr, 0, 0, 0} {}
cstring(const std::string& str) noexcept : cstring{str.data(), str.size(), 0, 0} {}
constexpr cstring(const cstring&) = default;
cstring& operator=(const cstring&) = default;
constexpr std::size_t size() const noexcept { return size_; }
constexpr std::size_t length() const noexcept { return size_; }
constexpr std::size_t max_size() const noexcept {
return (std::numeric_limits<std::size_t>::max)();
}
constexpr bool empty() const noexcept { return size_ == 0; }
constexpr const char* begin() const noexcept { return str_; }
constexpr const char* end() const noexcept { return str_ + size_; }
constexpr const char* cbegin() const noexcept { return begin(); }
constexpr const char* cend() const noexcept { return end(); }
constexpr const char& operator(std::size_t i) const { return str_[i]; }
constexpr const char& at(std::size_t i) const {
return (i < size_) ? str_[i]
: (throw std::out_of_range{"cstring::at"}, str_[0]);
}
constexpr const char& front() const { return str_[0]; }
constexpr const char& back() const { return str_[size_ - 1]; }
constexpr const char* data() const noexcept { return str_; }
constexpr cstring remove_prefix(std::size_t n) const {
return {str_ + n, size_ - n};
}
constexpr cstring add_prefix(std::size_t n) const {
return {str_ - n, size_ + n};
}
constexpr cstring remove_suffix(std::size_t n) const {
return {str_, size_ - n};
}
constexpr cstring add_suffix(std::size_t n) const {
return {str_, size_ + n};
}
constexpr cstring substr(std::size_t pos, std::size_t n) const {
return {str_ + pos, n};
}
constexpr int compare(cstring other) const {
return (size_ == other.size_) ? detail::StrCompare(str_, other.str_, size_)
: ((size_ > other.size_) ? 1 : -1);
}
friend constexpr bool operator==(cstring lhs, cstring rhs) {
return lhs.compare(rhs) == 0;
}
friend constexpr bool operator!=(cstring lhs, cstring rhs) {
return !(lhs == rhs);
}
std::string append(cstring s) const {
return std::string{str_, size_}.append(s.str_, s.size_);
}
friend std::string operator+(cstring lhs, cstring rhs) {
return std::string{lhs.str_, lhs.size_} + std::string{rhs.str_, rhs.size_};
}
friend std::ostream& operator<<(std::ostream& os, cstring str) {
os.write(str.str_, str.size_);
return os;
}
operator std::string() const { return std::string{str_, size_}; }
};
c++ c++11
New contributor
$endgroup$
add a comment |
$begingroup$
I want to write a very simple std::string like compile-time const char* string.
I need to work with strings in the compiletime, just like with strings, I implemented basic functions.
class cstring final {
const char* str_;
std::size_t size_;
public:
constexpr cstring(const char* str, std::size_t size, std::size_t prefix = 0, std::size_t suffix = 0) noexcept
: str_{str + prefix},
size_{size - prefix - suffix} {}
template <std::size_t N>
constexpr cstring(const char (&str)[N]) noexcept : cstring{str, N - 1, 0, 0} {}
constexpr cstring() noexcept : cstring{nullptr, 0, 0, 0} {}
cstring(const std::string& str) noexcept : cstring{str.data(), str.size(), 0, 0} {}
constexpr cstring(const cstring&) = default;
cstring& operator=(const cstring&) = default;
constexpr std::size_t size() const noexcept { return size_; }
constexpr std::size_t length() const noexcept { return size_; }
constexpr std::size_t max_size() const noexcept {
return (std::numeric_limits<std::size_t>::max)();
}
constexpr bool empty() const noexcept { return size_ == 0; }
constexpr const char* begin() const noexcept { return str_; }
constexpr const char* end() const noexcept { return str_ + size_; }
constexpr const char* cbegin() const noexcept { return begin(); }
constexpr const char* cend() const noexcept { return end(); }
constexpr const char& operator(std::size_t i) const { return str_[i]; }
constexpr const char& at(std::size_t i) const {
return (i < size_) ? str_[i]
: (throw std::out_of_range{"cstring::at"}, str_[0]);
}
constexpr const char& front() const { return str_[0]; }
constexpr const char& back() const { return str_[size_ - 1]; }
constexpr const char* data() const noexcept { return str_; }
constexpr cstring remove_prefix(std::size_t n) const {
return {str_ + n, size_ - n};
}
constexpr cstring add_prefix(std::size_t n) const {
return {str_ - n, size_ + n};
}
constexpr cstring remove_suffix(std::size_t n) const {
return {str_, size_ - n};
}
constexpr cstring add_suffix(std::size_t n) const {
return {str_, size_ + n};
}
constexpr cstring substr(std::size_t pos, std::size_t n) const {
return {str_ + pos, n};
}
constexpr int compare(cstring other) const {
return (size_ == other.size_) ? detail::StrCompare(str_, other.str_, size_)
: ((size_ > other.size_) ? 1 : -1);
}
friend constexpr bool operator==(cstring lhs, cstring rhs) {
return lhs.compare(rhs) == 0;
}
friend constexpr bool operator!=(cstring lhs, cstring rhs) {
return !(lhs == rhs);
}
std::string append(cstring s) const {
return std::string{str_, size_}.append(s.str_, s.size_);
}
friend std::string operator+(cstring lhs, cstring rhs) {
return std::string{lhs.str_, lhs.size_} + std::string{rhs.str_, rhs.size_};
}
friend std::ostream& operator<<(std::ostream& os, cstring str) {
os.write(str.str_, str.size_);
return os;
}
operator std::string() const { return std::string{str_, size_}; }
};
c++ c++11
New contributor
$endgroup$
2
$begingroup$
Welcome to Code Review. Could you add some additional information to your code, e.g. if you tried to reproduce thestring_view
interface, what you want reviewers to focus on, and so on? Also, you want to add missing#include
s forstd::string
andstd::numeric_limits
. A usage example of your class would also be much appreciated.
$endgroup$
– Zeta
15 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
14 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
13 hours ago
add a comment |
$begingroup$
I want to write a very simple std::string like compile-time const char* string.
I need to work with strings in the compiletime, just like with strings, I implemented basic functions.
class cstring final {
const char* str_;
std::size_t size_;
public:
constexpr cstring(const char* str, std::size_t size, std::size_t prefix = 0, std::size_t suffix = 0) noexcept
: str_{str + prefix},
size_{size - prefix - suffix} {}
template <std::size_t N>
constexpr cstring(const char (&str)[N]) noexcept : cstring{str, N - 1, 0, 0} {}
constexpr cstring() noexcept : cstring{nullptr, 0, 0, 0} {}
cstring(const std::string& str) noexcept : cstring{str.data(), str.size(), 0, 0} {}
constexpr cstring(const cstring&) = default;
cstring& operator=(const cstring&) = default;
constexpr std::size_t size() const noexcept { return size_; }
constexpr std::size_t length() const noexcept { return size_; }
constexpr std::size_t max_size() const noexcept {
return (std::numeric_limits<std::size_t>::max)();
}
constexpr bool empty() const noexcept { return size_ == 0; }
constexpr const char* begin() const noexcept { return str_; }
constexpr const char* end() const noexcept { return str_ + size_; }
constexpr const char* cbegin() const noexcept { return begin(); }
constexpr const char* cend() const noexcept { return end(); }
constexpr const char& operator(std::size_t i) const { return str_[i]; }
constexpr const char& at(std::size_t i) const {
return (i < size_) ? str_[i]
: (throw std::out_of_range{"cstring::at"}, str_[0]);
}
constexpr const char& front() const { return str_[0]; }
constexpr const char& back() const { return str_[size_ - 1]; }
constexpr const char* data() const noexcept { return str_; }
constexpr cstring remove_prefix(std::size_t n) const {
return {str_ + n, size_ - n};
}
constexpr cstring add_prefix(std::size_t n) const {
return {str_ - n, size_ + n};
}
constexpr cstring remove_suffix(std::size_t n) const {
return {str_, size_ - n};
}
constexpr cstring add_suffix(std::size_t n) const {
return {str_, size_ + n};
}
constexpr cstring substr(std::size_t pos, std::size_t n) const {
return {str_ + pos, n};
}
constexpr int compare(cstring other) const {
return (size_ == other.size_) ? detail::StrCompare(str_, other.str_, size_)
: ((size_ > other.size_) ? 1 : -1);
}
friend constexpr bool operator==(cstring lhs, cstring rhs) {
return lhs.compare(rhs) == 0;
}
friend constexpr bool operator!=(cstring lhs, cstring rhs) {
return !(lhs == rhs);
}
std::string append(cstring s) const {
return std::string{str_, size_}.append(s.str_, s.size_);
}
friend std::string operator+(cstring lhs, cstring rhs) {
return std::string{lhs.str_, lhs.size_} + std::string{rhs.str_, rhs.size_};
}
friend std::ostream& operator<<(std::ostream& os, cstring str) {
os.write(str.str_, str.size_);
return os;
}
operator std::string() const { return std::string{str_, size_}; }
};
c++ c++11
New contributor
$endgroup$
I want to write a very simple std::string like compile-time const char* string.
I need to work with strings in the compiletime, just like with strings, I implemented basic functions.
class cstring final {
const char* str_;
std::size_t size_;
public:
constexpr cstring(const char* str, std::size_t size, std::size_t prefix = 0, std::size_t suffix = 0) noexcept
: str_{str + prefix},
size_{size - prefix - suffix} {}
template <std::size_t N>
constexpr cstring(const char (&str)[N]) noexcept : cstring{str, N - 1, 0, 0} {}
constexpr cstring() noexcept : cstring{nullptr, 0, 0, 0} {}
cstring(const std::string& str) noexcept : cstring{str.data(), str.size(), 0, 0} {}
constexpr cstring(const cstring&) = default;
cstring& operator=(const cstring&) = default;
constexpr std::size_t size() const noexcept { return size_; }
constexpr std::size_t length() const noexcept { return size_; }
constexpr std::size_t max_size() const noexcept {
return (std::numeric_limits<std::size_t>::max)();
}
constexpr bool empty() const noexcept { return size_ == 0; }
constexpr const char* begin() const noexcept { return str_; }
constexpr const char* end() const noexcept { return str_ + size_; }
constexpr const char* cbegin() const noexcept { return begin(); }
constexpr const char* cend() const noexcept { return end(); }
constexpr const char& operator(std::size_t i) const { return str_[i]; }
constexpr const char& at(std::size_t i) const {
return (i < size_) ? str_[i]
: (throw std::out_of_range{"cstring::at"}, str_[0]);
}
constexpr const char& front() const { return str_[0]; }
constexpr const char& back() const { return str_[size_ - 1]; }
constexpr const char* data() const noexcept { return str_; }
constexpr cstring remove_prefix(std::size_t n) const {
return {str_ + n, size_ - n};
}
constexpr cstring add_prefix(std::size_t n) const {
return {str_ - n, size_ + n};
}
constexpr cstring remove_suffix(std::size_t n) const {
return {str_, size_ - n};
}
constexpr cstring add_suffix(std::size_t n) const {
return {str_, size_ + n};
}
constexpr cstring substr(std::size_t pos, std::size_t n) const {
return {str_ + pos, n};
}
constexpr int compare(cstring other) const {
return (size_ == other.size_) ? detail::StrCompare(str_, other.str_, size_)
: ((size_ > other.size_) ? 1 : -1);
}
friend constexpr bool operator==(cstring lhs, cstring rhs) {
return lhs.compare(rhs) == 0;
}
friend constexpr bool operator!=(cstring lhs, cstring rhs) {
return !(lhs == rhs);
}
std::string append(cstring s) const {
return std::string{str_, size_}.append(s.str_, s.size_);
}
friend std::string operator+(cstring lhs, cstring rhs) {
return std::string{lhs.str_, lhs.size_} + std::string{rhs.str_, rhs.size_};
}
friend std::ostream& operator<<(std::ostream& os, cstring str) {
os.write(str.str_, str.size_);
return os;
}
operator std::string() const { return std::string{str_, size_}; }
};
c++ c++11
c++ c++11
New contributor
New contributor
New contributor
asked 16 hours ago
NeargyeNeargye
211
211
New contributor
New contributor
2
$begingroup$
Welcome to Code Review. Could you add some additional information to your code, e.g. if you tried to reproduce thestring_view
interface, what you want reviewers to focus on, and so on? Also, you want to add missing#include
s forstd::string
andstd::numeric_limits
. A usage example of your class would also be much appreciated.
$endgroup$
– Zeta
15 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
14 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
13 hours ago
add a comment |
2
$begingroup$
Welcome to Code Review. Could you add some additional information to your code, e.g. if you tried to reproduce thestring_view
interface, what you want reviewers to focus on, and so on? Also, you want to add missing#include
s forstd::string
andstd::numeric_limits
. A usage example of your class would also be much appreciated.
$endgroup$
– Zeta
15 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
14 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
13 hours ago
2
2
$begingroup$
Welcome to Code Review. Could you add some additional information to your code, e.g. if you tried to reproduce the
string_view
interface, what you want reviewers to focus on, and so on? Also, you want to add missing #include
s for std::string
and std::numeric_limits
. A usage example of your class would also be much appreciated.$endgroup$
– Zeta
15 hours ago
$begingroup$
Welcome to Code Review. Could you add some additional information to your code, e.g. if you tried to reproduce the
string_view
interface, what you want reviewers to focus on, and so on? Also, you want to add missing #include
s for std::string
and std::numeric_limits
. A usage example of your class would also be much appreciated.$endgroup$
– Zeta
15 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
14 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
14 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
13 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
13 hours ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
I would only ever mark polymorphic classes
final
. For them, there's a potential benefit to balance out the unnaturalness of not being able to inherit.You should really indent the contents of the class by one step. Though that could possibly be an artifact of only partially adapting to SE's markup.
Consider verifying that
prefix
andsuffix
have sensible values, at least in debug-mode (assert()
).The first ctor has sensible defaults for its last two parameters. Why not take advantage of that?
Is there a reason you only accept
std::string
, instead of generallystd::basic_string<char, std::char_traits<char>, AnyAllocator>
?You could use
!_size
instead of_size == 0
. Well, de gustibus.Your comparison is curious, but at least consistent.
I would suggest conforming to C++17
std::string_view
as closely as possible so you can later remove your custom class, and to ease the burden for users.
$endgroup$
$begingroup$
1. I will consider. The final is a habit from Java. 2. Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing. 3. I'll add a check. 4. Do you mean to make the constructor like this? cstring() : cstring{nullptr, 0} {} 5. Yes, i think std::basic_string<char, std::char_traits<char>, AnyAllocator> will be better. 6. Ok, will be noted. 7. Oh, i forgot add detail::StrCompare to src. Will be fix soon. 8. I'll think about whether I can upgrade the project to C++17
$endgroup$
– Neargye
13 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
13 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Neargye is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215267%2fstdstring-like-compile-time-const-char-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
I would only ever mark polymorphic classes
final
. For them, there's a potential benefit to balance out the unnaturalness of not being able to inherit.You should really indent the contents of the class by one step. Though that could possibly be an artifact of only partially adapting to SE's markup.
Consider verifying that
prefix
andsuffix
have sensible values, at least in debug-mode (assert()
).The first ctor has sensible defaults for its last two parameters. Why not take advantage of that?
Is there a reason you only accept
std::string
, instead of generallystd::basic_string<char, std::char_traits<char>, AnyAllocator>
?You could use
!_size
instead of_size == 0
. Well, de gustibus.Your comparison is curious, but at least consistent.
I would suggest conforming to C++17
std::string_view
as closely as possible so you can later remove your custom class, and to ease the burden for users.
$endgroup$
$begingroup$
1. I will consider. The final is a habit from Java. 2. Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing. 3. I'll add a check. 4. Do you mean to make the constructor like this? cstring() : cstring{nullptr, 0} {} 5. Yes, i think std::basic_string<char, std::char_traits<char>, AnyAllocator> will be better. 6. Ok, will be noted. 7. Oh, i forgot add detail::StrCompare to src. Will be fix soon. 8. I'll think about whether I can upgrade the project to C++17
$endgroup$
– Neargye
13 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
13 hours ago
add a comment |
$begingroup$
I would only ever mark polymorphic classes
final
. For them, there's a potential benefit to balance out the unnaturalness of not being able to inherit.You should really indent the contents of the class by one step. Though that could possibly be an artifact of only partially adapting to SE's markup.
Consider verifying that
prefix
andsuffix
have sensible values, at least in debug-mode (assert()
).The first ctor has sensible defaults for its last two parameters. Why not take advantage of that?
Is there a reason you only accept
std::string
, instead of generallystd::basic_string<char, std::char_traits<char>, AnyAllocator>
?You could use
!_size
instead of_size == 0
. Well, de gustibus.Your comparison is curious, but at least consistent.
I would suggest conforming to C++17
std::string_view
as closely as possible so you can later remove your custom class, and to ease the burden for users.
$endgroup$
$begingroup$
1. I will consider. The final is a habit from Java. 2. Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing. 3. I'll add a check. 4. Do you mean to make the constructor like this? cstring() : cstring{nullptr, 0} {} 5. Yes, i think std::basic_string<char, std::char_traits<char>, AnyAllocator> will be better. 6. Ok, will be noted. 7. Oh, i forgot add detail::StrCompare to src. Will be fix soon. 8. I'll think about whether I can upgrade the project to C++17
$endgroup$
– Neargye
13 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
13 hours ago
add a comment |
$begingroup$
I would only ever mark polymorphic classes
final
. For them, there's a potential benefit to balance out the unnaturalness of not being able to inherit.You should really indent the contents of the class by one step. Though that could possibly be an artifact of only partially adapting to SE's markup.
Consider verifying that
prefix
andsuffix
have sensible values, at least in debug-mode (assert()
).The first ctor has sensible defaults for its last two parameters. Why not take advantage of that?
Is there a reason you only accept
std::string
, instead of generallystd::basic_string<char, std::char_traits<char>, AnyAllocator>
?You could use
!_size
instead of_size == 0
. Well, de gustibus.Your comparison is curious, but at least consistent.
I would suggest conforming to C++17
std::string_view
as closely as possible so you can later remove your custom class, and to ease the burden for users.
$endgroup$
I would only ever mark polymorphic classes
final
. For them, there's a potential benefit to balance out the unnaturalness of not being able to inherit.You should really indent the contents of the class by one step. Though that could possibly be an artifact of only partially adapting to SE's markup.
Consider verifying that
prefix
andsuffix
have sensible values, at least in debug-mode (assert()
).The first ctor has sensible defaults for its last two parameters. Why not take advantage of that?
Is there a reason you only accept
std::string
, instead of generallystd::basic_string<char, std::char_traits<char>, AnyAllocator>
?You could use
!_size
instead of_size == 0
. Well, de gustibus.Your comparison is curious, but at least consistent.
I would suggest conforming to C++17
std::string_view
as closely as possible so you can later remove your custom class, and to ease the burden for users.
answered 14 hours ago
DeduplicatorDeduplicator
11.6k1850
11.6k1850
$begingroup$
1. I will consider. The final is a habit from Java. 2. Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing. 3. I'll add a check. 4. Do you mean to make the constructor like this? cstring() : cstring{nullptr, 0} {} 5. Yes, i think std::basic_string<char, std::char_traits<char>, AnyAllocator> will be better. 6. Ok, will be noted. 7. Oh, i forgot add detail::StrCompare to src. Will be fix soon. 8. I'll think about whether I can upgrade the project to C++17
$endgroup$
– Neargye
13 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
13 hours ago
add a comment |
$begingroup$
1. I will consider. The final is a habit from Java. 2. Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing. 3. I'll add a check. 4. Do you mean to make the constructor like this? cstring() : cstring{nullptr, 0} {} 5. Yes, i think std::basic_string<char, std::char_traits<char>, AnyAllocator> will be better. 6. Ok, will be noted. 7. Oh, i forgot add detail::StrCompare to src. Will be fix soon. 8. I'll think about whether I can upgrade the project to C++17
$endgroup$
– Neargye
13 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
13 hours ago
$begingroup$
1. I will consider. The final is a habit from Java. 2. Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing. 3. I'll add a check. 4. Do you mean to make the constructor like this? cstring() : cstring{nullptr, 0} {} 5. Yes, i think std::basic_string<char, std::char_traits<char>, AnyAllocator> will be better. 6. Ok, will be noted. 7. Oh, i forgot add detail::StrCompare to src. Will be fix soon. 8. I'll think about whether I can upgrade the project to C++17
$endgroup$
– Neargye
13 hours ago
$begingroup$
1. I will consider. The final is a habit from Java. 2. Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing. 3. I'll add a check. 4. Do you mean to make the constructor like this? cstring() : cstring{nullptr, 0} {} 5. Yes, i think std::basic_string<char, std::char_traits<char>, AnyAllocator> will be better. 6. Ok, will be noted. 7. Oh, i forgot add detail::StrCompare to src. Will be fix soon. 8. I'll think about whether I can upgrade the project to C++17
$endgroup$
– Neargye
13 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
13 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
13 hours ago
add a comment |
Neargye is a new contributor. Be nice, and check out our Code of Conduct.
Neargye is a new contributor. Be nice, and check out our Code of Conduct.
Neargye is a new contributor. Be nice, and check out our Code of Conduct.
Neargye is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215267%2fstdstring-like-compile-time-const-char-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
Welcome to Code Review. Could you add some additional information to your code, e.g. if you tried to reproduce the
string_view
interface, what you want reviewers to focus on, and so on? Also, you want to add missing#include
s forstd::string
andstd::numeric_limits
. A usage example of your class would also be much appreciated.$endgroup$
– Zeta
15 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
14 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
13 hours ago