Skip to main content
Filter by
Sorted by
Tagged with
3 votes
3 answers
277 views

AFAIK, the default parameters should not have space around the = sign. def foo(bar: str="baz") What is the convention when there are union types? def foo(bar: str | None=None) def foo(bar: ...
GrandeKnight's user avatar
4 votes
1 answer
136 views

Is it safe to use a namespace-scope static variable (i.e., internal linkage) as the default parameter for a function declared in a header? And if so, is it guaranteed that when making a defaulted call ...
JSQuareD's user avatar
  • 4,886
1 vote
1 answer
108 views

So I have a method with simple lambda functions I use to update my weights and I want to try different functions but I also want to have default parameter for the decay: void ema_update(int i, const ...
AnArrayOfFunctions's user avatar
-1 votes
1 answer
70 views

It's been quite a while (18+ years) since I've been coding in C++. I am running into a problem with using default parameters in a function, then trying to call that function with only the non ...
Jesse Knott's user avatar
0 votes
1 answer
37 views

Tree node structure: class BPlusNode: def __init__(self,isleaf = True,val=[],parent=None,children=[]): self.values = val self.children = children self.parent = parent ...
momo's user avatar
  • 3
1 vote
2 answers
608 views

I sometimes want to pass in a callback function as a parameter to my_function. However, I want the default behavior to simply do nothing. I find myself wanting to write the following invalid lines of ...
Pedro Contipelli's user avatar
0 votes
2 answers
204 views

It is generally, for good reason, considered unsafe to use mutable default arguments in python. On the other hand, it is quite annoying to always have to wrap everything in Optional and do the little ...
Hyperplane's user avatar
  • 1,721
2 votes
1 answer
75 views

Please excuse me if this is asked elsewhere (and provide a link!). I wasn't able to find an exact duplicate. Not sure if I'm even phrasing the Q correctly. As a minimal example: #include <cstdint&...
ardnew's user avatar
  • 2,146
-1 votes
1 answer
47 views

I guess I never looked careful enough at the code I added before. Can someone help elaborate on the signature of this function? It is from .net 3.5 code, there is no default parameter support. But ...
Ben's user avatar
  • 1,341
1 vote
2 answers
181 views

Suppose I have a function prototype which defaults several parameters: bool debug_log(char* text, int len, bool log_always = true, // Defaults to yes, log SRgba* ...
Rick C. Hodgin's user avatar
2 votes
3 answers
142 views

How would I make a function that takes address of another function as a parameter so that passing it is not necessary. My first solution was this: void empty_func() {} void func(void (*...
Kesto2's user avatar
  • 78
-1 votes
1 answer
233 views

Going through the python documentation, I came across below. Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, ...
Kraken's user avatar
  • 24.4k
-3 votes
2 answers
154 views

When default parameters are not specified, function overloading works. But, why doesn't function overloading work when default parameters are specified? This program takes two integers and compares ...
Kim_Yeon_Shin_01's user avatar
0 votes
0 answers
21 views

I am new to bash scripting and struggle to update a parameter with a default value. I observe some of my optional parameters are not getting updated according to the user input. Below is the ...
Barbara Gendron's user avatar
0 votes
1 answer
784 views

I am trying to build a small program in C++, to learn the preprocessor directives and how they actually work. The program is made up of 5 files: main.cpp, file1.h, file1.cpp, file2.h and file2.cpp In ...
X Y's user avatar
  • 259
0 votes
0 answers
77 views

I have a outer function foo that calls two inner functions, bar1 and bar2. Each inner function (bar) has default parameters. I'd like to be able to call foo and specify whichever parameters I want, ...
tmldwn's user avatar
  • 475
0 votes
2 answers
111 views

<body> <h1>Insert here:</h1> <button>Try</button> <input name='myName' type="text"> <h2>No one here</h2> <script&...
Luca's user avatar
  • 1
0 votes
2 answers
42 views

I would like to know if it is possible to use the function itself in its default parameter. function somename(a,b=somename()){ return a+b; } somename(10);
navedhn's user avatar
0 votes
0 answers
30 views

my_func.h class MyClass{ public: OtherClass otherclass; void func(); void func(OtherClass others); }; my_func.cpp #includ <my_func.h> void MyClass::func(){ func(this->otherclass); } ...
MinSu Park's user avatar
-2 votes
1 answer
58 views

I was reading this very informative question and answer and learned about this behavior for the first time: calling def foo(l=[]): l.append(1) print(l) foo() foo() foo([]) foo() prints [1] [...
DoodleVib's user avatar
  • 156
1 vote
2 answers
278 views

I have a function which creates an object and inserts it into a container. In most cases, the object type is the same as that of the container elements. Then, I don't want to have to specify the ...
RL-S's user avatar
  • 997
2 votes
1 answer
193 views

I'm struggling to make this code work template <typename T, typename U = int, auto... Params> class Foo {}; int main() { auto foo1 = Foo<int, int, 1, 2, 3>{}; auto foo2 = Foo<...
Joshua Jakowlew's user avatar
0 votes
2 answers
138 views

Im trying to create a function that takes 6 arguments, 3 of which are "optional" given that I tried giving them default values. This function takes in the 6 values and gives them to another ...
João Roquette Saldanha's user avatar
1 vote
2 answers
652 views

I'm writing a quick Powershell script to import modules and update some default parameters on various machines. I'm running into an issue where in my script when I add $PSDefaultParameterValues to ...
jbuck99's user avatar
  • 13
0 votes
0 answers
75 views

I have inherited code that looks similar to the following: struct A { typedef void * X; }; struct B { typedef void * Y; }; struct foo { void bar (A::X x, int a, int b) { return; } ...
Zak's user avatar
  • 12.7k
0 votes
1 answer
596 views

Okay so there's a lot of similar questions here but none that actually address this. What if I want to save the default parameters of a function on a separated object, in a separated file and then I ...
Daniel Guedes's user avatar
0 votes
0 answers
28 views

I have a function 'transfer(int arr[12][7], char letter = 'a')' that is in another class with a header files that takes in 2 parameters. I am trying to set the letter as a default parameter, so I ...
Kadia64's user avatar
0 votes
0 answers
46 views

import pandas as pd import os import time from datetime import datetime path = "/Users/tommasomasaracchio/Documents/pythonfolder" def key_stats(gather="Total Deb/Equity (mrg)"): ...
fieshf's user avatar
  • 1
4 votes
1 answer
15k views

I have the following function that converts a file to Base64. How do I make it so this function accepts a default value for the file path if one is not entered? B64 -f $filePath function B64{ ...
I am Jakoby's user avatar
1 vote
2 answers
65 views

I want to create a function with default params, but I want to use one default param and then use a custom value for the following one. For instance, function greet(name, greeting = 'Hey', question = '...
user avatar
0 votes
1 answer
132 views

I have recently read about mutable default parameters in Python. For some reason, I came up with an idea of using it like this: data = [3, 4, 1, 8, 5, 9, 2, 6, 7] def get_min(checked=[]): global ...
Oleksandr Novik's user avatar
5 votes
1 answer
17k views

currently have been facing this issue using tailwind and making rehusable react components where you can pass as a prop some styles as tailwind classes. The actual problem is with the "pb-{number}...
Joyboy's user avatar
  • 99
1 vote
2 answers
791 views

Relatively new to Python, I find myself having to evaluate a lot of arguments in functions/static methods and I was thinking if there is a user-friendly way to do this, so I ended up writing a ...
gkampolis's user avatar
  • 115
0 votes
2 answers
1k views

I created a function that should return an object with user data. I want the function to accept an object as a parameter and I'd like this object to be defined inside the function with all the values ...
uma's user avatar
  • 13
0 votes
2 answers
375 views

I'm trying to create a smart pointer and stumbled over the code below. Since I'm pretty new to C++, its syntax is yet something I have to get used to. Below you can see the most important part of the ...
Scorpia's user avatar
  • 465
3 votes
2 answers
1k views

I am having trouble in Typescript passing default values to a function similar to pick from lodash. The function accepts an object of known (non-generic) interface and a set of keys to pick and return ...
mitsos1os's user avatar
  • 2,310
0 votes
1 answer
6k views

My class has a method with default parameters whose values are derived from an injected parameter: class Slack @Inject constructor( private val brokerSettings: BrokerSettings ) { fun alert( ...
Tim Baverstock's user avatar
3 votes
1 answer
160 views

template <class V, class K> class Pair { public: Pair(const K& key, const V& value = initial) { // what should "initial" be here? // ... } } For example if ...
roniabusayeed's user avatar
6 votes
3 answers
3k views

So I want to create a function that generates consecutive numbers from 'start' to 'end' as many as 'size'. For the iteration, it will be calculated inside the function. But I have problem to set ...
Yusuf Syam's user avatar
1 vote
1 answer
179 views

I have a function with multiple optional parameters whose default values are conditional on the non-optional parameters. It currently looks like this: def foo(x, y, option_1=None, option_2=None, ...
CSStudent7782's user avatar
3 votes
1 answer
3k views

I am converting some existing JS code into TS, and we've used a pattern I can't figure out how to express correctly with typescript : function getVehicles({ brandFields = false, ownerFields = ...
VincentGuinaudeau's user avatar
5 votes
2 answers
3k views

I want some of my function parameter to be optional, so I used default parameter as follow : fun defaultparameter(param1: String = "", param2: String = "", param3: Int = 0) this ...
XCarb's user avatar
  • 997
0 votes
1 answer
2k views

I am trying to understand how None as the default parameter works. I have a function that has 4 parameters, first is non-default followed by 3 parameters that are set =None. Function: send(name, ...
ires's user avatar
  • 17
1 vote
1 answer
320 views

The following program does not compile: #include <utility> #include <iostream> #define N 4 template <unsigned int I> unsigned int g() { return I; } template <unsigned int... I&...
francesco's user avatar
  • 7,617
8 votes
1 answer
1k views

This is what I want to implement: void fun({ bool Function(int i) predicate = (i) => false, }) { // do something with 'predicate(something)' } But I am getting the error: The default value of ...
Midhunraj R Pillai's user avatar
0 votes
1 answer
40 views

I'm trying to understand what happens when a variable gets assigned a value inside a function's argument list. For example: myFunction(arr, newArr = []) Does this mean I'm initializing newArr within ...
ezeYaniv's user avatar
  • 600
0 votes
1 answer
66 views

I am writing a Function with 2 Parameters, 1st is integer type marked [[maybe_unused]] and 2nd is Boolean Type with Default Argument false. int preOrderTraversial([[maybe_unused]] int searchData, bool ...
Haider Sultan's user avatar
0 votes
1 answer
55 views

Take this simplified example: Command.h: class Command { public: template<typename Func> Command(Func newToExecute) : toExecute([&newToExecute](){newToExecute();}) { } void ...
xeretis's user avatar
  • 75
-3 votes
1 answer
197 views

The list, x, isn't initialized to the parameter default value each time the function is operated, but remains in the previous state and adds a new value. That's how the function was executed 5 times, ...
J. SungHoon's user avatar
2 votes
1 answer
802 views

I have come across that only parameters at the END of a paramater list can have a default value as VALUES are assigned by position in a function as how it is defined below def greeting(a,b=7): ...
venkatraman Balasubramanian's user avatar

1
2 3 4 5
8