literals

Typescript - Why can't this string literal type be inferred?

一个人想着一个人 提交于 2019-12-05 07:04:34
The following snippet does not pass the type check: type TaskType = 'SIMPLE' | 'COMPLEX' interface TaskDefinition { name: string, task: string, taskType: TaskType }; const test: TaskDefinition = { name: '', task: '', taskType: 'SIMPLE' // This is fine }; const tasks : TaskDefinition[] = ["apples", "pears"].map(i => { return { name: i, task: i, taskType: 'SIMPLE' // This one is not }; }) { name: string; task: string; taskType: string; }[] is not assignable to type TaskDefinition []. Try it It seems that taskType gets inferred as string instead of TaskType despite the target type being

How to return a string literal from a function

假装没事ソ 提交于 2019-12-05 05:45:49
I am always confused about return a string literal or a string from a function. I was told that there might be memory leak because you don't know when the memory will be deleted? For example, in the code below, how to implement foo() so as to make the output of the code is "Hello World"? void foo ( ) // you can add parameters here. { } int main () { char *c; foo ( ); printf ("%s",c); return 0; } Also, if the return type of foo() is not void, but you can return char* , what should it be? I'm assuming we cannot modify main. To get your program working without a leak, you need something to have

How do I type literal binary in VB.NET?

删除回忆录丶 提交于 2019-12-05 04:07:48
How do you type binary literals in VB.NET? &HFF // literal Hex -- OK &b11111111 // literal Binary -- how do I do this? codymanix You could define it as string and then parse it: myBin = Convert.ToInt32("1010101010", 2) As of VB.NET 15 there is now support for binary literals: Dim mask As Integer = &B00101010 You can also include underscores as digit separators to make the number more readable without changing the value: Dim mask As Integer = &B0010_1010 Expanding on codymanix's answer... You could wrap this in an Extension on Strings, and add type checking... something along the lines of:

Difference between modes of literal control

China☆狼群 提交于 2019-12-05 03:24:41
What is the difference between the passthrough and Transform modes of literal control? Could you post an example, too? Muhammad Akhtar There are different Literal Modes Literal.Mode PassThrough : The contents of the control are not modified. Encode : The contents of the control are converted to an HTML-encoded string. Transform : Unsupported markup-language elements are removed from the contents of the control. If the Literal control is rendered on a browser that supports HTML or XHTML, the control's contents are not modified. Have a look at this MSDN article http://msdn.microsoft.com/en-us

Creating a list with >255 elements

有些话、适合烂在心里 提交于 2019-12-05 01:11:10
Ok, so I'm writing some python code (I don't write python much, I'm more used to java and C). Anyway, so I have collection of integer literals I need to store. (Ideally >10,000 of them, currently I've only got 1000 of them) I would have liked to be accessing the literals by file IO, or by accessing there source API, but that is disallowed. And not ontopic anyway. So I have the literals put into a list: src=list(0,1,2,2,2,0,1,2,... ,2,1,2,1,1,0,2,1) #some code that uses the src But when I try to run the file it comes up with an error because there are more than 255 arguments. So the constructor

Passing Array to Python Spark Lit Function

↘锁芯ラ 提交于 2019-12-04 23:34:18
Let's say I have a numpy array a that contains the numbers 1-10. So a is [1 2 3 4 5 6 7 8 9 10]. Now, I also have a Python Spark dataframe to which I want to add my numpy array a. I figure that a column of literals will do the job. So I do the following: df = df.withColumn("NewColumn", F.lit(a)) This doesn't work. The error is "Unsupported literal type class java.util.ArrayList". Now, if I try just one element of the array, as follows, it works. df = df.withColumn("NewColumn", F.lit(a[0])) Is there a way I can do what I'm trying? I've been working on the task I want to complete for days and

How do I write a map literal in C++11? [duplicate]

筅森魡賤 提交于 2019-12-04 23:33:04
This question already has answers here : Initializing a static std::map<int, int> in C++ (11 answers) Closed 5 years ago . In Python, I can write a map literal like this: mymap = {"one" : 1, "two" : 2, "three" : 3} How can I do the equivalent in C++11? You can actually do this: std::map<std::string, int> mymap = {{"one", 1}, {"two", 2}, {"three", 3}}; What is actually happening here is that std::map stores an std::pair of the key value types, in this case std::pair<const std::string,int> . This is only possible because of c++11's new uniform initialization syntax which in this case calls a

Why does 1.__add__(2) not work out? [duplicate]

我的梦境 提交于 2019-12-04 23:06:11
This question already exists : Closed 7 years ago . Possible Duplicate: accessing a python int literals methods In Python, everything is an object . But then again, why doesn't the following snippet work? 1.__add__(2) However, this does work: n = 1 n.__add__(2) What is the difference between n and 1 ? Isn't it a design failure that it doesn't work? For instance, it does work with string literals as well. "one".__add__("two") For comparison, it works well on other purely object oriented languages too. Let's take a closer look at this compiling c# example: Console.WriteLine(100.ToString()); Then

How can I use a dynamic format string with the format! macro?

半腔热情 提交于 2019-12-04 22:53:43
I just started learning Rust, and I'm making some small tools to help me understand the language. I have a problem formatting a String using the format! macro. As format! takes a literal, I am not able pass my string to it. I want to do this to dynamically add strings into the current string for use in a view engine. I'm open for suggestions if there might be a better way to do it. let test = String::from("Test: {}"); let test2 = String::from("Not working!"); println!(test, test2); What I actually want to achieve is the below example, where main.html contains {content} . use std::io::prelude::

Why must a string be constructed at run-time? [duplicate]

情到浓时终转凉″ 提交于 2019-12-04 22:22:51
This question already has an answer here: Is it possible to use std::string in a constexpr? 4 answers Can C-Strings or std::string s be created as constexpr or must they be created at run-time? With gcc 4.9.2 I can do this: constexpr const char foo[] = "blee"; (Sadly the November 2013 Customer Technology Preview does not allow Visual Studio to support this: https://stackoverflow.com/a/29255013/2642059 ) But even with gcc 4.9.2 I cannot do this: constexpr const std::string foo = "blee"; I get the error: error: the type 'const string {aka const std::basic_string<char>}' of constexpr variable