c++17

Range-v3's zip function works with temporaries coming from other Range-v3's functions but not with others

浪尽此生 提交于 2020-12-13 03:29:44
问题 (This is kind of a follow up to this other question.) Original question The following code works just fine #include <boost/range/adaptor/transformed.hpp> #include <cmath> #include <range/v3/view/zip.hpp> #include <string> #include <vector> int main() { auto vec1 = std::vector<int>{1,2,3}; auto vec2 = std::vector<std::string>{"uno","due","tre"}; auto sqrt = [](auto x){ return std::sqrt(x); }; auto vec3 = vec1 | boost::adaptors::transformed(sqrt); for (auto const& i : ranges::views::zip(vec1,

How is const std::wstring encoded and how to change to UTF-16

不羁的心 提交于 2020-12-12 09:41:58
问题 I created this minimum working C++ example snippet to compare bytes (by their hex representation) in a std::string and a std::wstring when defining a string with german non-ASCII characters in either type. #include <iostream> #include <iomanip> #include <string> int main(int, char**) { std::wstring wstr = L"äöüß"; std::string str = "äöüß"; for ( unsigned char c : str ) { std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<unsigned short>(c) << ' '; } std::cout << std:

How is const std::wstring encoded and how to change to UTF-16

泄露秘密 提交于 2020-12-12 09:38:07
问题 I created this minimum working C++ example snippet to compare bytes (by their hex representation) in a std::string and a std::wstring when defining a string with german non-ASCII characters in either type. #include <iostream> #include <iomanip> #include <string> int main(int, char**) { std::wstring wstr = L"äöüß"; std::string str = "äöüß"; for ( unsigned char c : str ) { std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<unsigned short>(c) << ' '; } std::cout << std:

C++: How to partially deduce template arguments from make_shared

拟墨画扇 提交于 2020-12-12 02:53:40
问题 In order to circumvent the restriction on partially supplied explicit template arguments, I embed the struct from which I want to deduce the class template parameters ( Internal ) into a second struct ( Container ). I would like to enable the user of the code to create e.g. shared pointers of the resulting type. By writing my own create function within the struct, this works just fine. #include <memory> /// Container that is used in order to partially specify template arguments template <int

C++: How to partially deduce template arguments from make_shared

孤人 提交于 2020-12-12 02:53:16
问题 In order to circumvent the restriction on partially supplied explicit template arguments, I embed the struct from which I want to deduce the class template parameters ( Internal ) into a second struct ( Container ). I would like to enable the user of the code to create e.g. shared pointers of the resulting type. By writing my own create function within the struct, this works just fine. #include <memory> /// Container that is used in order to partially specify template arguments template <int

C++ std::filesystem::filesystem_error exception trying to read system volume information, etc

江枫思渺然 提交于 2020-12-11 02:19:38
问题 I am trying to work around an exception being thrown when trying to recursively walk through all files in root drives, like C:, D:, etc. I am using GCC compiler version 9.3.0 on Mingw64. I got std::filesystem::filesystem_error when trying to read system volume information, example output: Checking "D:\\System Volume Information" filesystem error: cannot increment recursive directory iterator: Invalid argument Code snippet: try { for (auto& p : fs::recursive_directory_iterator(dp, fs:

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

Can C++17 be used together with CUDA using clang?

给你一囗甜甜゛ 提交于 2020-12-02 05:59:06
问题 As far as using nvcc , one needs to use the corresponding gcc (currently max. 5.4 I believe) in conjunction. This of course somewhat prevents one from using C++17 on the host side. Since C++17 can be compiled using clang 5 and upwards (see here), and one can compile cuda code as well (see here), is it possible to use both C++17 and CUDA at the same time (or can there be problems, e.g. with the CUDA runtime)? 回答1: Yes, as you already guessed the CUDA clang frontend is indeed ahead in C++