literals

Should I use _T or _TEXT on C++ string literals?

拥有回忆 提交于 2019-12-18 12:08:13
问题 For example: // This will become either SomeMethodA or SomeMethodW, // depending on whether _UNICODE is defined. SomeMethod( _T( "My String Literal" ) ); // Becomes either AnotherMethodA or AnotherMethodW. AnotherMethod( _TEXT( "My Text" ) ); I've seen both. _T seems to be for brevity and _TEXT for clarity. Is this merely a subjective programmer preference or is it more technical than that? For instance, if I use one over the other, will my code not compile against a particular system or some

Is there a best practice for writing maps literal style in Java?

落花浮王杯 提交于 2019-12-18 10:33:30
问题 In short, if you want to write a map of e.g. constants in Java, which in e.g. Python and Javascript you would write as a literal, T<String,String> CONSTANTS = { "CONSTANT_NAME_0": CONSTANT_VALUE_0 , "CONSTANT_NAME_1": CONSTANT_VALUE_1 , "CONSTANT_NAME_2": CONSTANT_VALUE_2 , //... } ; is there a Class or any preset Object that you can use for writing a data structure like that? 回答1: Constants ? I'd use an enum. public enum Constants { NAME_1("Value1"), NAME_2("Value2"), NAME_3("Value3");

how to match string literal type when concat string in typescript

╄→гoц情女王★ 提交于 2019-12-18 09:45:57
问题 type TA = 'App' | 'Area'; type TB = 'getAppDetail' | 'getAreaDetail'; const a: TA = 'App'; const b: TB = `get${a}Detail`; But get${a}Detail returns a string type. And it doesn't match type TB. Is there any solutions to solve the problem here? Thanks 回答1: What you want is probably something like a string literal expression type or Regex-validated string type. Currently both are not possible unfortunately. The type system requires to be statically analyzable - in your example, you have a simple

Type error when testing a function with a negative number

☆樱花仙子☆ 提交于 2019-12-18 09:16:11
问题 I am following along with the Learn you a Haskell for great good , I have implemented take' : take' :: (Ord i, Num i) => i -> [a] -> [a] take' n _ | n <= 0 = [] take' _ [] = [] take' n (x:xs) = x: take' (n-1) xs When testing the function with: take' -2 [2] instead of getting an empty list, I have this message: Non type-variable argument in the constraint: Num (i -> [a] -> [a]) (Use FlexibleContexts to permit this) When checking that ‘it’ has the inferred type it :: forall i a t. (Num i, Num t

Using C am I right in thinking that literals beginning with multiple zeros are considered octal?

余生长醉 提交于 2019-12-18 08:56:22
问题 In the following C code are octal literals used for all these defines? Even if they start with multiple zeros? #define TCL_REG_BASIC 000000 /* BREs (convenience). */ #define TCL_REG_EXTENDED 000001 /* EREs. */ #define TCL_REG_ADVF 000002 /* Advanced features in EREs. */ #define TCL_REG_ADVANCED 000003 /* AREs (which are also EREs). */ #define TCL_REG_QUOTE 000004 /* No special characters, none. */ #define TCL_REG_NOCASE 000010 /* Ignore case. */ #define TCL_REG_NOSUB 000020 /* Don't care

Strange Haskell expression with type Num ([Char] -> t) => t

末鹿安然 提交于 2019-12-18 07:46:40
问题 While doing some exercises in GHCi I typed and got the following> ghci> (1 "one") <interactive>:187:1: No instance for (Num ([Char] -> a0)) arising from a use of ‘it’ In a stmt of an interactive GHCi command: print it which is an error, howeve if I ask GHCi for the type of the expression it does not give any error: ghci> :type (1 "one") (1 "one") :: Num ([Char] -> t) => t What is the meaning of (1 "one") ? Why does this expression gives an error, but GHCi tells it is well typed? What is the

Trying to pass string literals as template arguments [duplicate]

混江龙づ霸主 提交于 2019-12-17 19:59:22
问题 This question already has answers here : Passing a string literal as a parameter to a C++ template class (13 answers) Closed 2 years ago . I'm trying to find a comfortable way to pass string literals as template arguments. I'm not caring about supporting the widest possible number of compilers, I'm using the latest version of g++ with --std=c++0x . I've tried a lot of possible solutions but all have disappointed me. I'm sort of giving up, but first I'd like to know why a couple of them failed

python ValueError: invalid literal for float()

强颜欢笑 提交于 2019-12-17 19:12:41
问题 I've a script which reads temperature data: def get_temp(socket, channels): data = {} for ch in channels: socket.sendall('KRDG? %s\n' % ch) time.sleep(0.2) temp = socket.recv(32).rstrip('\r\n') data[ch] = float(temp) Sometimes, the script fails on the line which converts the values to float: File "./projector.py", line 129, in get_temp data[ch] = float(temp) ValueError: invalid literal for float(): +135.057E+0 +078.260E+0 +00029 but this is NOT an invalid literal. If I enter this into any

Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

∥☆過路亽.° 提交于 2019-12-17 17:53:33
问题 Why does Python 3 allow "00" as a literal for 0 but not allow "01" as a literal for 1? Is there a good reason? This inconsistency baffles me. (And we're talking about Python 3, which purposely broke backward compatibility in order to achieve goals like consistency.) For example: >>> from datetime import time >>> time(16, 00) datetime.time(16, 0) >>> time(16, 01) File "<stdin>", line 1 time(16, 01) ^ SyntaxError: invalid token >>> 回答1: Per https://docs.python.org/3/reference/lexical_analysis

How can I make PowerShell handle [ or ] in file name well?

坚强是说给别人听的谎言 提交于 2019-12-17 17:13:57
问题 I modified PowerShell script from PowerShell - Batch change files encoding To UTF-8. # Modified version of https://stackoverflow.com/q/18684793 [Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US' $Encoding = New-Object System.Text.UTF8Encoding($True) # If UTF8Encoding($False), It will be UTF-8 without BOM $source = "C:\Users\AKULA\Desktop\SRC" # source directory $destination = "C:\Users\AKULA\Desktop\DST" # destination directory if (!(Test-Path $destination)) { New-Item -Path