string-view Questions
6
Solved
The implementation of these methods seems straightforward to me and they would make usage of std::string and std::string_view more interchangeable. After all, std::string_view has constructors whic...
Carloscarlota asked 24/1, 2019 at 11:53
4
Solved
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<string_view>
#include<...
Kilpatrick asked 10/6, 2022 at 13:58
6
Solved
Is there a safe standard way to convert std::string_view to int?
Since C++11 std::string lets us use stoi to convert to int:
std::string str = "12345";
int i1 = stoi(str); // Works, have i1 =...
Bille asked 17/6, 2019 at 15:31
2
Solved
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 i...
Unfriendly asked 23/1, 2018 at 13:9
4
Solved
I've been adding std::string_views to some old code for representing string like config params, as it provides a read only view, which is faster due to no need for copying.
However, one cannot conc...
Evangelin asked 24/8, 2022 at 19:4
3
Solved
I just knew that C++17 introduced std::string_view. It doesn't hold any string, instead, it points to a string. If so, I'm confused by the case below:
std::string str = "abc";
std::string...
Photoneutron asked 26/6, 2023 at 9:51
3
Solved
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_N...
Planetary asked 24/1, 2023 at 2:3
2
So I am reading code written for newer versions of CPP and frequently see string_view literals used almost exclusively, even in simple use cases.
For example:
std::cout<<"Hello world&quo...
Embryologist asked 19/1, 2023 at 10:9
2
Solved
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 ref...
Ormazd asked 23/9, 2016 at 5:55
2
I would like to know how to properly handle a string input in a function, if I know I will have to make a copy inside of it to place it inside a container.
I was thinking of doing it like this:
voi...
Portfolio asked 9/9, 2022 at 12:45
2
Solved
The std::stringstream initialization constructor accepts const string& as a parameter:
explicit stringstream (const string& str,
ios_base::openmode which = ios_base::in | ios_base::out);
...
Garretson asked 3/9, 2022 at 4:19
3
There is an implicit conversion from std::string to std::string_view and it's not considered unsafe, even though this surely may cause a lot of dangling references if the programmer is not careful....
Bathrobe asked 28/11, 2017 at 6:27
1
Solved
I have read some questions and documentation, and I guess answer is yes, since string_view will never touch the pointed to stuff, but I am a still bit confused if this is legal:
std::vector<char...
Kilk asked 7/6, 2022 at 16:35
2
Solved
Since C++17, we have std::string_view, a light-weight view into a contiguous sequence of characters that avoids unnecessary copying of data. Instead of having a const std::string& parameter, it...
Piceous asked 19/6, 2017 at 17:26
0
As the title states.
Why does a std::string_view comparison not consider equal memory addresses.
According to the standard and equally the implementation of MSVC's STL implementation which I checke...
Hodosh asked 16/5, 2022 at 5:10
4
Solved
I'm trying to write a simple template function which accepts all possible basic_string_view but i always get the compiler error "no matching overloaded function found".
I don't know the r...
Ethology asked 4/5, 2022 at 10:55
6
I read The most elegant way to iterate the words of a string and enjoyed the succinctness of the answer. Now I want to do the same for string_view. Problem is, stringstream can't take a string_view...
Sowder asked 28/12, 2017 at 18:28
1
Solved
I would like to use the fmt library to create a string_view from my format args. There is plenty documented about passing in a compile-time string as the format string, however, I want to output a ...
Glove asked 22/2, 2022 at 13:25
2
std::transform, as of C++20, is declared constexpr. I have a bunch of string utility functions that take std::string arguments, but a lot of the usage ends up just passing in small, short, characte...
Ashcroft asked 5/1, 2022 at 19:39
1
Solved
To allow std::string construction from std::string_viewthere is a template constructor
template<class T>
explicit basic_string(const T& t, const Allocator& alloc = Allocator());
whic...
Castiron asked 25/11, 2021 at 15:0
3
Solved
It is possible to create a std::string_view from a std::string easily. But if I want to create a string view of a range of std::string using the iterators of the std::string does not work.
Here is ...
Ragamuffin asked 27/8, 2021 at 13:13
1
Solved
I am writing a lot of parser code where string_view excels, and have become fond of the type. I recently read ArthurO'Dwyer's article std::string_view is a borrow type, where he concludes that stri...
Rabble asked 23/10, 2021 at 7:59
4
Solved
Suppose I have the following code:
void some_function(std::string_view view) {
std::cout << view << '\n';
}
int main() {
some_function(std::string{"hello, world"}); // ???
...
Unconcern asked 12/9, 2021 at 7:32
1
Solved
Consider this snippet:
#include <iostream>
#include <string>
#include <string_view>
using namespace std::literals;
class A
{
public:
std::string to_string() const noexcept
{
...
Concurrent asked 23/8, 2021 at 13:26
3
Solved
cppreference uses it to describe
std::string_view:
std::basic_string_view (C++17) - a
lightweight non-owning read-only view into a subsequence of a string.
devtut
and
sodocumentation
use ...
Pacer asked 7/8, 2021 at 6:18
1 Next >
© 2022 - 2025 — McMap. All rights reserved.