Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

std::string_view

$
0
0
Can string_views be used in combination with setters? I would like to have something like the code below. Unfortunately, my constructors are ambiguous for the second invocation. The view is capable of reducing the number of methods, std::string, C string, but could it be used as well in combination with move semantics? Or is the view solely intended for "you may look at the string, but you are not allowed to own it."? #include <iostream> #include <string> #include <string_view> using namespace std; struct Str { explicit Str(string_view str) : m_str(str) {} explicit Str(string &&str) : m_str(std::move(str)) {} string m_str; }; int main() { string a = "a"; Str as = Str(a); Str bs = Str("b"); }

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>