auto

Why does `auto` not adopt the constexpr'ness of its initializing expression?

孤人 提交于 2021-02-20 04:23:05
问题 Why doesn't defining a variable with auto keyword carry the constexpr 'ness of the expression used to initialize it? As an example, consider the following code: #include <string_view> constexpr std::string_view f() { return "hello"; } static constexpr std::string_view g() { constexpr auto x = f(); // (*) return x.substr(1, 3); } int foo() { return g().length(); } With GCC 10.2 and --std=c++20 -fsanitize=undefined -O3 , this compiles into: foo(): mov eax, 3 ret But if we remove the constexpr

How to perfectly forward `auto&&` in a generic lambda?

允我心安 提交于 2021-02-15 10:16:34
问题 C++14 supports generic lambdas. However, the following code is rejected by clang 3.4. #include <utility> void f(int); void f(int&); int main() { [](auto&& v) { f(std::forward<auto>(v)); }(8); // error } How to perfectly forward auto&& in a generic lambda? 回答1: auto is not a type so I’m not surprised this doesn’t work. But can’t you use decltype ? [](auto&& v) { f(std::forward<decltype(v)>(v)); }(8); Scott Meyers has more details. 来源: https://stackoverflow.com/questions/24535430/how-to

How to perfectly forward `auto&&` in a generic lambda?

不羁岁月 提交于 2021-02-15 10:16:25
问题 C++14 supports generic lambdas. However, the following code is rejected by clang 3.4. #include <utility> void f(int); void f(int&); int main() { [](auto&& v) { f(std::forward<auto>(v)); }(8); // error } How to perfectly forward auto&& in a generic lambda? 回答1: auto is not a type so I’m not surprised this doesn’t work. But can’t you use decltype ? [](auto&& v) { f(std::forward<decltype(v)>(v)); }(8); Scott Meyers has more details. 来源: https://stackoverflow.com/questions/24535430/how-to

Is a pointer to function (sometimes/always?) a function declarator?

风流意气都作罢 提交于 2021-02-09 05:10:57
问题 (This question has been broken out from the discussion to this answer, which highlights CWG 1892) Some paragraphs of the standard applies specific rules to function declarators ; e.g. [dcl.spec.auto]/3 regarding placeholder types [ emphasis mine]: The placeholder type can appear with a function declarator in the decl-specifier-seq , type-specifier-seq , conversion-function-id , or trailing-return-type , in any context where such a declarator is valid. If the function declarator includes a

Function with auto parameter compiles using GCC but does not compile using Visual C++

谁说胖子不能爱 提交于 2021-01-29 09:16:59
问题 Please considere the following code-snippet: #include <iostream> void print(auto arg) { std::cout << arg << std::endl; } int main() { print("Hi"); return 0; } As you can see here (https://godbolt.org/z/2GSrXs) using GCC the code compiles and runs fine. As you can see here (https://godbolt.org/z/rtR6w9) using Visual C++ the code does not compile and results in the error message: <source>(3): error C3533: a parameter cannot have a type that contains 'auto' . It seems to me that this feature has

Function with auto parameter compiles using GCC but does not compile using Visual C++

别说谁变了你拦得住时间么 提交于 2021-01-29 09:08:06
问题 Please considere the following code-snippet: #include <iostream> void print(auto arg) { std::cout << arg << std::endl; } int main() { print("Hi"); return 0; } As you can see here (https://godbolt.org/z/2GSrXs) using GCC the code compiles and runs fine. As you can see here (https://godbolt.org/z/rtR6w9) using Visual C++ the code does not compile and results in the error message: <source>(3): error C3533: a parameter cannot have a type that contains 'auto' . It seems to me that this feature has

How to merge shard bin files into one

ぐ巨炮叔叔 提交于 2021-01-28 18:22:41
问题 I just trained a Google Auto ML Vision model and exported as TensorFlowJS to implement it in React Native. The Problem I am facing: Google splits the weights into 6 different shard*.bin files. As it is a graph model, I can't use the tensorflowjs_converter to leverage the --weight_shard_size_bytes setting. I did not find any other way to import it into my React Native app than by using the BundleResourcesIO function which needs one bin file. The model should be bundled locally. Does anyone

Why does auto deduce this variable as double and not float? [duplicate]

时光怂恿深爱的人放手 提交于 2021-01-19 14:24:14
问题 This question already has answers here : Why floating point value such as 3.14 are considered as double by default in MSVC? (5 answers) All floats are doubles? (3 answers) How a floating point literal is treated either double or float in Visual C++? (2 answers) why sizeof(13.33) is 8 bytes? (5 answers) What is the type of the value 1.0e+1 (4 answers) Closed 1 year ago . In the snippet below, auto deduces the variable to double , but I want float . auto one = 3.5; Does it always use double for

Why does auto deduce this variable as double and not float? [duplicate]

两盒软妹~` 提交于 2021-01-19 14:23:34
问题 This question already has answers here : Why floating point value such as 3.14 are considered as double by default in MSVC? (5 answers) All floats are doubles? (3 answers) How a floating point literal is treated either double or float in Visual C++? (2 answers) why sizeof(13.33) is 8 bytes? (5 answers) What is the type of the value 1.0e+1 (4 answers) Closed 1 year ago . In the snippet below, auto deduces the variable to double , but I want float . auto one = 3.5; Does it always use double for

Why is my StackView not working? Elements are completely displaced

让人想犯罪 __ 提交于 2020-12-08 05:09:40
问题 Hey my StackView is doing nothing, there are two problems: The first is that the elements on the VC are completely displaced when I turn around the simulator or change the device, so the StackView is not doing what it should do! The second thing is that the StackView is covering the navigation bar and I don't know how to make it visible. Can someone help me? import UIKit class RegisterViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { let