type-deduction

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

Type constraints for automatic function constraint deduction in Haskell

老子叫甜甜 提交于 2021-02-07 13:13:52
问题 For educational purposes I am playing around with trees in Haskell. I have Tree a type defined like this data Tree a = EmptyTree | Node a (Tree a) (Tree a) and a lot of functions that share a basic constraint - Ord a - so they have types like treeInsert :: Ord a => a -> Tree a -> Tree a treeMake :: Ord a => [a] -> Tree a and so on. I can also define Tree a like this data Ord a => Tree a = EmptyTree | Node a (Tree a) (Tree a) but I can not simplify my functions and omit the extra Ord a to be

User-Defined Deduction Guides in C++20

十年热恋 提交于 2021-02-05 05:57:18
问题 I'm working with std::variant and std::visit using the "overload" pattern that looks like this: #include <iostream> #include <variant> template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; }; template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>; int main(void) { std::variant<int, float> var; auto fs = overloaded { [](int var) {std::cout << "var is int" << std::endl;}, [](float var) {std::cout << "var is float" << std::endl;} }; var = 0; std::visit(fs, var); var =

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

For loop index type deduction best practice

主宰稳场 提交于 2020-03-17 08:42:47
问题 Let's say, I have a container c of a type that provides a size() method and I want to loop over this container while keeping track of each item's index: for (/*TODO*/ i = 0; i < c.size(); i++) {...} In a post-C++11 world, where automatic type deduction solves so many problems nicely. What should we use in place of the TODO above? The only thing that seems correct to me, no matter what the type of size() is, is the following: for (decltype(c.size()) i = 0; i < c.size(); i++) {...} But this

Is auto in template parameter list in lambdas part of the standard?

时光毁灭记忆、已成空白 提交于 2020-02-27 23:06:45
问题 Today, I stumbled across the following code snippet: #include <utility> int main() { auto a = [](std::pair<auto, auto> value) { }; a(std::pair<int, bool>{ 3, true }); } http://cpp.sh/5p34 I have only one question: is this code supported by the standard? It compiles in GCC (with -std=c++14 ), but not clang or Visual Studio 2015 (VC++14). This seems like it should be part of the standard because if lambdas should have the same template support as regular functions, then this should be supported