std

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

How this c++ code runs without definition of function

我只是一个虾纸丫 提交于 2020-05-23 11:15:24
问题 Can anyone explain the logic behind the working of defined function in this program. This gives the correct output in this case even after commenting the whole logic of function. #include <iostream> using namespace std; void swap(int *a, int *b) { /* int temp=0; temp= *a; *a= *b; *b=temp; */ } int main() { int x, y; cout << "This program is the demo of function call by pointer \n\n"; cout << "Enter the value of x & y \n"; cout << "x: "; cin >> x; cout << "y: "; cin >> y; cout << "Value befor

How this c++ code runs without definition of function

我怕爱的太早我们不能终老 提交于 2020-05-23 11:14:05
问题 Can anyone explain the logic behind the working of defined function in this program. This gives the correct output in this case even after commenting the whole logic of function. #include <iostream> using namespace std; void swap(int *a, int *b) { /* int temp=0; temp= *a; *a= *b; *b=temp; */ } int main() { int x, y; cout << "This program is the demo of function call by pointer \n\n"; cout << "Enter the value of x & y \n"; cout << "x: "; cin >> x; cout << "y: "; cin >> y; cout << "Value befor

Why must std::visit have a single return type?

戏子无情 提交于 2020-05-14 18:17:05
问题 While playing around with std::variant and std::visit the following question came up: Consider the following code: using Variant = std::variant<int, float, double>; auto lambda = [](auto&& variant) { std::visit( [](auto&& arg) { using T = std::decay_t<decltype(arg)>; if constexpr (std::is_same_v<T, int>) { std::cout << "int\n"; } else if (std::is_same_v<T, float>) { std::cout << "float\n"; } else { std::cout << "double\n"; } }, variant); }; It works fine as the following examples show: lambda

std optional: No such file or directory

混江龙づ霸主 提交于 2020-05-14 17:35:11
问题 I tried to compile the following program with different compilers (including gcc 6.1) : #include <optional> int main() { std::optional<int> o1; } Output is main.cpp:1:20: fatal error: optional: No such file or directory #include optional This is even true for the examples given here: http://en.cppreference.com/w/cpp/utility/optional/optional Any clues why? 回答1: std::optional will be part of the C++17 standard, but if you want to use before then you will have to use std::experimental::optional

Android Studio CMake - shared library missing libc++_shared.so? Can CMake bundle this?

隐身守侯 提交于 2020-05-11 04:30:06
问题 Now that Android Studio 2.2 is released officially, I'm migrating from my old ndk-build process to try and use CMake within AS. As I'm incorporating several codebases from within my company (that I can't edit) that make heavy use of C++11 code (including the dreaded std::to_string() method), the only way I can compile is with a select few configuration options - all of which I discovered earlier when beginning work with ndk-build. (see below) So everything compiles again and builds into the

How to hash std::string?

时光毁灭记忆、已成空白 提交于 2020-05-11 04:07:10
问题 I'm making a little utility to help me remember passwords by repetition. I'd like to enter password to be remembered only once every day and not before each session. Of course, I wouldn't store a password itself, but would gladly store its hash. So, what are the easiest ways to get a hash from std::string using the C++ Standard Library? 回答1: For a quick solution involving no external libraries, you can use hash<std::string> to hash string s. It's defined by including the header files hash_map

Why is std::hash not guaranteed to be deterministic?

不羁岁月 提交于 2020-05-09 20:15:09
问题 Hereafter, we use N4140 (C++14 Standard). According to § 17.6.3.4 Hash requirements , 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 for a given execution of the program . — end note ] and § 20.9.12 Class template hash says ... the instantiation hash<Key> shall: (1.1) — satisfy the Hash requirements (17.6.3.4) ... (1.2) — ... This means a hash value of

Long regex expression causes error

南笙酒味 提交于 2020-05-09 08:19:08
问题 This std::regex line("[\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s]"); line causes this Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at memory location 0x000000F751EFEAB0. Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000. Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at