To allow std::string construction from std::string_viewthere is a template constructor
template
explicit basic_string(const T& t, const Allocator& alloc = Allocator());
which is enabled only if const T& is convertible to…
Assume we have a simple getter method in a class that returns a const reference to a std::string member:
const std::string& getString() const noexcept { return someString; }
With the advent of std::string_view in C++17, I wonder whether it has any…
My question is motivated by this answer on stackoverflow, https://stackoverflow.com/a/48082010/5360439. To quote,
Q: How you convert a std::string_view to a const char*?
A: Simply do a std::string(string_view_object).c_str() to get a guaranteed…
I need to split a std::string at all spaces. The resulting range should however transform it's element to std::string_views. I'm struggling with the "element type" of the range. I guess, the type is something like a c_str. How can I transform the…
I've found string_view from new C++17 standard a bit redundant.
We've got a quite verbose collection of simple mechanisms for passing data to callee, without much overhead and now there is one another which is also specific only to one container…
I saw both std::string_view and std::string have symmetric operator==() and for std::string it has the constructor to accept std::string_view and operator to convert itself to std::string_view. So when we try to use operator==() compare between…
I just ran into some misunderstanding:
at least in libc++ implementation std::experimental::string_view has the following concise implementation:
template
class basic_string_view {
public:
typedef _CharT…
I am new to C++17 and to std::string_view.
I learned that they are not null terminated and must be handled with care.
Is this the right way to printf() one?
#include
#include
int main()
{
std::string_view sv{"Hallo!"};
…
Let's say you have an std::unordered_set .
You have an std::string_view object that you want to search for in the container. Problem is, you don't want to create a std::string from your std::string_view, as this kind of defeats the…
Boost provides two different implementations of string_view, which will be a part of C++17:
boost::string_ref in utility/string_ref.hpp
boost::string_view in core/string_view.hpp
Are there any significant differences between these? Which should be…
Following code gives the dangling pointer error.
std::vector> c;
for (auto& b : c) {
const auto& [s, i] = b;
std::string_view v = s.substr(i);
std::cout << v;
}
I think that b holds…
I've been playing around with the std::string_view library and I have been contemplating on changing a code base I have been working on to use std::string_view as much as possible. However, in many of the threads that I have read on the subject of…
I would like to remove the reliance of #define macros in my code, and I'm unable to achieve the same functionality with constexpr.
To be practical, consider the following example:
#define PRODUCT_NAME "CloysterHPC"
constexpr const char* productName…
While implementing C++1z's std::basic_string_view to use it on older compilers, I encountered a problem with the stream output operator overload for it.
Basically, it has to output the contents referenced by the string_view while not relying on any…
I have a relatively simple use case: I want to associate a trait to a class which will return some user defined string, namely some user-defined registration ID. As this registrations are supposed to be defined at compile-time I would like it to be…