string-view

Differences between boost::string_ref and boost::string_view

混江龙づ霸主 提交于 2021-02-18 05:11:53
问题 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 preferred going forward? Note: I noticed in Boost 1.61, boost::log has deprecated string_ref in favor of string_view; perhaps that's an indicator? (http://www.boost.org/users/history/version_1_61_0.html) 回答1: Funnily enough right now I'm at the

Avoiding the func(char *) api on embedded

心已入冬 提交于 2021-01-29 08:14:24
问题 Note: I heavily changed my question to be more specific, but I will keep the old question at end of the post, in case it is useful to anyone. New Question I am developing an embedded application which uses the following types to represent strings : string literals(null terminated by default) std::array<char,size> (not null terminated) std::string_view I would like to have a function that accepts all of them in a uniform way. The only problem is that if the input is a string literal I will

How to create a constexpr array with a sequence of string_views at compile time?

醉酒当歌 提交于 2021-01-27 06:12:06
问题 I would like to create a constexpr std::array<std::string_view, ConstexprNumber> . It should for example contain constexpr std::strings_view's like this: "text0", "text1", "text2", ..... "textn" I came up with the following initial solution: #include <iostream> #include <array> #include <utility> #include <string> #include <string_view> // Number of strings that we want to generate constexpr size_t NumberOfTextsToGenerate = 10u; // constexpr function to build a string constexpr std::string

How to convert std::string_view to double?

旧时模样 提交于 2020-12-04 15:59:43
问题 I'm writing a c++ parser for a custom option file for an application. I have a loop that reads lines in the form of option=value from a text file where value must be converted to double . In pseudocode it does the following: while(not EOF) statement <- read_from_file useful_statement <- remove whitespaces, comments, etc from statement equal_position <- find '=' in useful_statement option_str <- useful_statement[0:equal_position) value_str <- useful_statement[equal_position:end) find_option

How to convert std::string_view to double?

佐手、 提交于 2020-12-04 15:58:13
问题 I'm writing a c++ parser for a custom option file for an application. I have a loop that reads lines in the form of option=value from a text file where value must be converted to double . In pseudocode it does the following: while(not EOF) statement <- read_from_file useful_statement <- remove whitespaces, comments, etc from statement equal_position <- find '=' in useful_statement option_str <- useful_statement[0:equal_position) value_str <- useful_statement[equal_position:end) find_option

How to convert std::string_view to double?

最后都变了- 提交于 2020-12-04 15:58:09
问题 I'm writing a c++ parser for a custom option file for an application. I have a loop that reads lines in the form of option=value from a text file where value must be converted to double . In pseudocode it does the following: while(not EOF) statement <- read_from_file useful_statement <- remove whitespaces, comments, etc from statement equal_position <- find '=' in useful_statement option_str <- useful_statement[0:equal_position) value_str <- useful_statement[equal_position:end) find_option

How to correctly create std::string from a std::string_view?

你离开我真会死。 提交于 2020-07-09 02:47:19
问题 I have a class: class Symbol_t { public: Symbol_t( const char* rawName ) { memcpy( m_V, rawName, 6 * sizeof( char ) ); }; string_view strVw() const { return string_view( m_V, 6 ); }; private: char m_V[6]; }; // class Symbol_t and there is a lib-func that I can't modify: extern bool loadData( const string& strSymbol ); If there is a local variable: Symbol_t symbol( "123456" ); When I need to call loadData, I dare not do it like this: loadData( string( symbol.strVw().begin(), symbol.strVw().end

std::string_view compile time hashing

做~自己de王妃 提交于 2020-05-27 06:27:04
问题 It seems the std::hash functions for the C++17 string_view are not constexpr's. It seems to me that a string view bound to a const char[] could be hashed at compile time (which would be very sweet), or is there anything which prevents this? 回答1: Since C++14 (see 17.6.3.4 Hash requirements, table 26), we have: The value returned shall depend only on the argument k for the duration of the program. [Note: Thus all evaluations of the expression h(k) with the same value for k yield the same result

std::string_view compile time hashing

落爺英雄遲暮 提交于 2020-05-27 06:26:32
问题 It seems the std::hash functions for the C++17 string_view are not constexpr's. It seems to me that a string view bound to a const char[] could be hashed at compile time (which would be very sweet), or is there anything which prevents this? 回答1: Since C++14 (see 17.6.3.4 Hash requirements, table 26), we have: The value returned shall depend only on the argument k for the duration of the program. [Note: Thus all evaluations of the expression h(k) with the same value for k yield the same result