Why does the reverse() function in the Swift standard library return ReverseRandomAccessCollection?

It is an performance optimization for both time and memory. The ReverseRandomAccessCollection presents the elements of the original array in reverse order, without the need to create a new array and copying all elements (as long as the original array is not mutated). You can access the reversed elements with subscripts: let el0 = arr[arr.startIndex] … Read more

Why does str.split not take keyword arguments?

See this bug and its superseder. str.split() is a native function in CPython, and as such exhibits the behavior described here: CPython implementation detail: An implementation may provide built-in functions whose positional parameters do not have names, even if they are ‘named’ for the purpose of documentation, and which therefore cannot be supplied by keyword. … Read more

Concatenating strings doesn’t work as expected [closed]

Your code, as written, works. You’re probably trying to achieve something unrelated, but similar: std::string c = “hello” + “world”; This doesn’t work because for C++ this seems like you’re trying to add two char pointers. Instead, you need to convert at least one of the char* literals to a std::string. Either you can do … Read more

How to check if a file exists in Go?

To check if a file doesn’t exist, equivalent to Python’s if not os.path.exists(filename): if _, err := os.Stat(“/path/to/whatever”); errors.Is(err, os.ErrNotExist) { // path/to/whatever does not exist } To check if a file exists, equivalent to Python’s if os.path.exists(filename): Edited: per recent comments if _, err := os.Stat(“/path/to/whatever”); err == nil { // path/to/whatever exists } … Read more

Are int8_t and uint8_t intended to be char types?

From § 18.4.1 [cstdint.syn] of the C++0x FDIS (N3290), int8_t is an optional typedef that is specified as follows: namespace std { typedef signed integer type int8_t; // optional //… } // namespace std § 3.9.1 [basic.fundamental] states: There are five standard signed integer types: “signed char”, “short int”, “int”, “long int”, and “long long … Read more