std::string like compile-time const char* stringChecking endianness at compile-timeFunction to convert from const char * to char**Compile Time Constant MapEfficient compile-time directed graphCompile-time printf format checkingCompile-time printf-style format checkingCompile-time wildcard pattern matchingCompile-time plugin systemCompile-time plugin system (2)Compile-time string hash
Is having access to past exams cheating and, if yes, could it be proven just by a good grade?
Space in array system equations
The bar has been raised
Is there an equal sign with wider gap?
Things to avoid when using voltage regulators?
Reverse string, can I make it faster?
Is it possible to have an Abelian group under two different binary operations but the binary operations are not distributive?
Is it true that real estate prices mainly go up?
Should QA ask requirements to developers?
Time travel short story where dinosaur doesn't taste like chicken
How much stiffer are 23c tires over 28c?
Built-In Shelves/Bookcases - IKEA vs Built
Grey hair or white hair
PTIJ: How can I halachically kill a vampire?
Good for you! in Russian
Why is Beresheet doing a only a one-way trip?
Norms on fields
Why does Captain Marvel assume the people on this planet know this?
Adding an additional "order by" column gives me a much worse plan
Set and print content of environment variable in cmd.exe subshell?
Look through the portal of every day
How to pass a string to a command that expects a file?
Making a sword in the stone, in a medieval world without magic
Is there an elementary proof that there are infinitely many primes that are *not* completely split in an abelian extension?
std::string like compile-time const char* string
Checking endianness at compile-timeFunction to convert from const char * to char**Compile Time Constant MapEfficient compile-time directed graphCompile-time printf format checkingCompile-time printf-style format checkingCompile-time wildcard pattern matchingCompile-time plugin systemCompile-time plugin system (2)Compile-time string hash
$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 : cstringstr, N - 1, 0, 0
constexpr cstring() noexcept : cstringnullptr, 0, 0, 0
cstring(const std::string& str) noexcept : cstringstr.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::stringstr_, size_.append(s.str_, s.size_);
friend std::string operator+(cstring lhs, cstring rhs)
return std::stringlhs.str_, lhs.size_ + std::stringrhs.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::stringstr_, 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 : cstringstr, N - 1, 0, 0
constexpr cstring() noexcept : cstringnullptr, 0, 0, 0
cstring(const std::string& str) noexcept : cstringstr.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::stringstr_, size_.append(s.str_, s.size_);
friend std::string operator+(cstring lhs, cstring rhs)
return std::stringlhs.str_, lhs.size_ + std::stringrhs.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::stringstr_, 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
8 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
6 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
5 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 : cstringstr, N - 1, 0, 0
constexpr cstring() noexcept : cstringnullptr, 0, 0, 0
cstring(const std::string& str) noexcept : cstringstr.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::stringstr_, size_.append(s.str_, s.size_);
friend std::string operator+(cstring lhs, cstring rhs)
return std::stringlhs.str_, lhs.size_ + std::stringrhs.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::stringstr_, 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 : cstringstr, N - 1, 0, 0
constexpr cstring() noexcept : cstringnullptr, 0, 0, 0
cstring(const std::string& str) noexcept : cstringstr.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::stringstr_, size_.append(s.str_, s.size_);
friend std::string operator+(cstring lhs, cstring rhs)
return std::stringlhs.str_, lhs.size_ + std::stringrhs.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::stringstr_, size_;
;
c++ c++11
c++ c++11
New contributor
New contributor
New contributor
asked 8 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
8 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
6 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
5 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
8 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
6 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
5 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
8 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
8 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
6 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
6 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
5 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
5 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() : cstringnullptr, 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
5 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
5 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() : cstringnullptr, 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
5 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
5 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() : cstringnullptr, 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
5 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
5 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 6 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() : cstringnullptr, 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
5 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
5 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() : cstringnullptr, 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
5 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
5 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() : cstringnullptr, 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
5 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() : cstringnullptr, 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
5 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
5 hours ago
$begingroup$
re 4: Yes, that's it.
$endgroup$
– Deduplicator
5 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
-c++, c++11
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
8 hours ago
$begingroup$
Some indentation would be nice.
$endgroup$
– Quuxplusone
6 hours ago
$begingroup$
Sorry for the indents, they disappeared during writing answer. Overlooked, correct when editing.
$endgroup$
– Neargye
5 hours ago