default-parameters

Default lambda as templated parameter of a function

若如初见. 提交于 2020-08-20 03:09:20
问题 Consider the following code template<bool b, typename T> void foo(const T& t = []() {}) { // implementation here } void bar() { foo<true>([&](){ /* implementation here */ }); // this compiles foo<true>(); // this doesn't compile } In the case that doesn't compile I get the following errors: error C2672: 'foo': no matching overloaded function found error C2783: 'void foo(const T&)': could not deduce template argument for 'T' I think it's clear what I want to achieve: let foo be called with and

Lexical declaration problems with default params [duplicate]

☆樱花仙子☆ 提交于 2020-01-30 10:54:48
问题 This question already has an answer here : JS default argument value from variable: why must identifier be different? [duplicate] (1 answer) Closed 2 years ago . I'm having some problems when defining some functions after declaring a class . I've used default params before when declaring functions, but I don't know if I can use a function or class as default parameter too. My code is this const Matrix = class {/*...some code...*/} const sigmoid = function(A, flag = false, factor = 1, Matrix =

“Redefinition” of default template parameter

淺唱寂寞╮ 提交于 2020-01-24 02:45:07
问题 I have a strange compilation warning for the following code, with Visual C++ 2010: #include <iostream> class test { public: template<class obj> class inner { private: // Line 11: template<int index, bool unused = true> struct AttributeName; private: template<bool b> struct AttributeName<0,b> { static inline const char* get() { return "prop"; } }; public: typedef AttributeName<0> propname; }; typedef inner<test> description; }; int main() { test t; std::cout << test::description::propname::get

Technical reason for no default parameters in Java

百般思念 提交于 2020-01-14 07:15:49
问题 I've been looking around to try to find what the reasoning is behind not including default parameters for functions in Java. I'm aware that it's possible to simulate the behavior, either with varargs or else by creating several overloaded functions that accept fewer parameters, and call the real function that takes all parameters. However, neither of these options match the clarity and ease-of-use of, e.g. C++'s syntax. Does anyone know if there's a solid technical reason that would make

Technical reason for no default parameters in Java

与世无争的帅哥 提交于 2020-01-14 07:15:32
问题 I've been looking around to try to find what the reasoning is behind not including default parameters for functions in Java. I'm aware that it's possible to simulate the behavior, either with varargs or else by creating several overloaded functions that accept fewer parameters, and call the real function that takes all parameters. However, neither of these options match the clarity and ease-of-use of, e.g. C++'s syntax. Does anyone know if there's a solid technical reason that would make

JavaScript function with optional parameters [duplicate]

不打扰是莪最后的温柔 提交于 2020-01-10 14:58:53
问题 This question already has answers here : How to overload functions in javascript? (13 answers) Closed 4 years ago . I'm new to JavaScript coming from Python background. In Python parameters can be passed as key and value as such: def printinfo( name, age = 35 ): print "Name: ", name print "Age ", age return; Then the function could be called as such: printinfo( age=50, name="miki" ) printinfo( name="miki" ) Can such parameters be passing in JavaScript functions? I want to be able to pass one

Fortran 2003 / 2008: Elegant default arguments?

空扰寡人 提交于 2020-01-10 01:35:57
问题 In fortran, we can define default arguments. However, if an optional argument is not present, it can also not be set. When using arguments as keyword arguments with default values, this leads to awkward constructs like PROGRAM PDEFAULT CALL SUB CALL SUB(3) CONTAINS SUBROUTINE SUB(VAL) INTEGER, OPTIONAL :: VAL INTEGER :: AVAL ! short for "actual val" IF(PRESENT(VAL)) THEN AVAL = VAL ELSE AVAL = -1 ! default value END IF WRITE(*,'("AVAL is ", I0)') AVAL END SUBROUTINE SUB END PROGRAM PDEFAULT

Invocation of methods with default parameters in scala higher-order function

瘦欲@ 提交于 2020-01-05 13:38:34
问题 Supposedly I have a method that has one default parameter. I want to pass it as an argument to another method. How do I call the passed-in method with its default parameter ? def printNum(i: Int = 4): Unit = { println(i) } def doStuff(printFunc: (Int) => Unit): Unit = { // How to call printFunc with its default parameter printFunc() } doStuff(printNum) 回答1: I am afraid you cannot. Default parameter is property of methods, just like named arguments and things like this. When you pass it as a

Invocation of methods with default parameters in scala higher-order function

橙三吉。 提交于 2020-01-05 13:38:27
问题 Supposedly I have a method that has one default parameter. I want to pass it as an argument to another method. How do I call the passed-in method with its default parameter ? def printNum(i: Int = 4): Unit = { println(i) } def doStuff(printFunc: (Int) => Unit): Unit = { // How to call printFunc with its default parameter printFunc() } doStuff(printNum) 回答1: I am afraid you cannot. Default parameter is property of methods, just like named arguments and things like this. When you pass it as a

Invocation of methods with default parameters in scala higher-order function

自古美人都是妖i 提交于 2020-01-05 13:38:11
问题 Supposedly I have a method that has one default parameter. I want to pass it as an argument to another method. How do I call the passed-in method with its default parameter ? def printNum(i: Int = 4): Unit = { println(i) } def doStuff(printFunc: (Int) => Unit): Unit = { // How to call printFunc with its default parameter printFunc() } doStuff(printNum) 回答1: I am afraid you cannot. Default parameter is property of methods, just like named arguments and things like this. When you pass it as a