default-value

Default values for array arguments

▼魔方 西西 提交于 2019-11-30 01:29:44
问题 Just playing around a little with C++. What I really want to do is to be able to setup a function with default values defined for an array or pointer argument. To keep things simple, let's just use an array. Like so: void experimentA(char a[3] = {'a', 'b', 'c'}); The compiler (LLVM GCC 4.2 with GNU99) complains "Expected expression". That is quite obtuse, but I was told by colleagues that this is happening because the 'value' I'm trying to assign is statically allocated, whereas the variable

Get default value of an input using jQuery

≡放荡痞女 提交于 2019-11-30 00:50:32
问题 $(".box_yazi2").each(function () { var default_value = this.value; $(this).css('color', '#555'); // this could be in the style sheet instead $(this).focus(function () { if (this.value == default_value) { this.value = ''; $(this).css('color', '#000'); } }); $(this).blur(function () { if (this.value == '') { $(this).css('color', '#555'); this.value = default_value; } }); }); This function of default value of input doesnt work in FF, but perfectly works in IE and ofcourse the input itself looks

XML serialization and DefaultValue(“”) related problem in c#

冷暖自知 提交于 2019-11-29 18:12:37
问题 my class property has default value which will be serialize. public class DeclaredValue { [XmlElement(ElementName = "Amount", DataType = "double", IsNullable = false), DefaultValue(999)] public double Amount { get; set; } [XmlElement(ElementName = "Reference2", DataType = "string", IsNullable = false), DefaultValue("")] public string Reference2 { get; set; } } so we create instance of DeclaredValue class and provide value for Reference2 property and do not assign anything for Amount. so when

Using class/static methods as default parameter values within methods of the same class

时光怂恿深爱的人放手 提交于 2019-11-29 15:09:43
问题 I'd like to do something like this: class SillyWalk(object): @staticmethod def is_silly_enough(walk): return (False, "It's never silly enough") def walk(self, appraisal_method=is_silly_enough): self.do_stuff() (was_good_enough, reason) = appraisal_method(self) if not was_good_enough: self.execute_self_modifying_code(reason) return appraisal_method def do_stuff(self): pass def execute_self_modifying_code(self, problem): from __future__ import deepjuju deepjuju.kiss_booboo_better(self, problem)

MySQL default date() + 14 days, for a column?

跟風遠走 提交于 2019-11-29 15:01:40
I was wondering if the following is possible to do through MySQL or will it have to be done using PHP. Task - "Expiry Date" User enters product name User clicks submit form button Data is POST'ed and then sent to MySQL Expiry date = date now + 14 days What I am trying to achieve is a way for mysql to insert an "expiry_date" in a table column that will equal 14 days after the date the row was created in that table. e.g. product_name - foo entry_date - 2012-02-01 expiry_date - 2012-02-15 I have a feeling it may not be possible to do in mysql unless using a stored procedure. I am happy to do it

How to tell XmlSerializer to serialize properties with [DefautValue(…)] always?

依然范特西╮ 提交于 2019-11-29 13:10:38
I am using DefaultValue attribute for the proper PropertyGrid behavior (it shows values different from default in bold). Now if I want to serialize shown object with the use of XmlSerializer there will be no entries in xml-file for properties with default values. What is the easiest way to tell XmlSerializer to serialize these still? I need that to support "versions", so when I change default value later in the code - serialized property gets value it had serialized with, not "latest" one. I can think about following: Override behavior of PropertyGrid (use custom attribute, so it will be

Why when I deserialize with JSON.NET ignores my default value?

£可爱£侵袭症+ 提交于 2019-11-29 13:10:24
I'm using JSON.NET as my main serializer. This is my model, look that I've setted some JSONProperties and a DefaultValue . public class AssignmentContentItem { [JsonProperty("Id")] public string Id { get; set; } [JsonProperty("Qty")] [DefaultValue(1)] public int Quantity { get; set; } } When I serialize a List<AssignmentContentItem> , it doing a good work: private static JsonSerializerSettings s = new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }; OUTPUT: [{"Id":"Q0"},{"Id":"Q4"},{"Id":"Q7"}] But when I'd like to

Scala - Currying and default arguments

為{幸葍}努か 提交于 2019-11-29 13:02:10
问题 I have a function with two parameter lists that I am trying to partially apply and use with currying. The second parameter list contains arguments that all have default values (but not implicit). Something like this: def test(a: Int)(b: Int = 2, c: Int = 3) { println(a + ", " + b + ", " + c); } Now, the following is all fine: test(1)(2, 3); test(1)(2); test(1)(c=3); test(1)(); Now if I define: def partial = test(1) _; Then the following can be done: partial(2, 3); Can someone explain why I

How does the Python range function have a default parameter before the actual one?

爱⌒轻易说出口 提交于 2019-11-29 12:41:09
问题 So I'm writing a function that takes an optional list and extends it to the length specified. Rather than writing it as foo(n, list=None) I was wondering how I might emulate the behavior of Python's range function which works like: >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(5, 10) [5, 6, 7, 8, 9] That is, with the default parameter first. For reference trying to naively set this up returns a syntax error: def foo(x=10, y): return x + y SyntaxError: non-default argument follows

Any more concise way to set default values?

柔情痞子 提交于 2019-11-29 11:00:00
Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise. Is there any better or more concise way than following code to set default value of variables? $v = isset($v) ? $v : "default value"; Here is a shorter syntax: isset($v) || $v="default value"; TL;DR - No, that expression can't be made any shorter. What you want is for the shortened ternary expression to perform an implicit isset() . This has been discussed on the mailing list and an ifsetor RFC has been created that covers