standard-library

Why is Haskell missing “obvious” Typeclasses

℡╲_俬逩灬. 提交于 2019-11-28 16:38:39
Consider the Object-Oriented Languages: Most people coming from an object-oriented programming background, are familiar with the common and intuitive interfaces in various languages that capture the essence of Java's Collection & List interfaces. Collection refers to a collection of objects which doesn't necessarily have an natural ordering/indexing. A List is a collection which has a natural ordering/indexing. These interfaces abstract many library data-structures in Java, as do their equivalent interfaces in other languages, and an intimate understanding of these interfaces are required to

What are the differences amongst Python's “__get*__” and “_del*__” methods?

巧了我就是萌 提交于 2019-11-28 16:01:45
问题 I just started learning Python a few months ago, and I'm trying to understand the differences between the different __get*__ methods: __get__ __getattr__ __getattribute__ __getitem___ And their __del*__ equivalents: __del__ __delattr__ __delete__ __delitem__ What are the differences between these? When should I use one over the other? Is there a specific reason why most of the __get*__ methods have __set*__ equivalents, but there is no __setattribute__ ? 回答1: The documentation for every

Design of std::ifstream class

放肆的年华 提交于 2019-11-28 13:46:21
Those of us who have seen the beauty of STL try to use it as much as possible, and also encourage others to use it wherever we see them using raw pointers and arrays . Scott Meyers have written a whole book on STL, with title Effective STL . Yet what happened to the developers of ifstream that they preferred char* over std::string . I wonder why the first parameter of ifstream::open() is of type const char* , instead of const std::string & . Please have a look at it's signature: void open(const char * filename, ios_base::openmode mode = ios_base::in ); Why this? Why not this: void open(const

c++ valgrind shows memory leak in hello world [duplicate]

。_饼干妹妹 提交于 2019-11-28 07:47:31
问题 This question already has answers here : Valgrind: Memory still reachable with trivial program using <iostream> (3 answers) Closed last year . Code of my program is #include <iostream> int main(int argc, const char *argv[]) { std::cout << "hello world!\n"; return 0; } I compiled it with flags -Wpedantic -pedantic-errors -std=c++11 -g -Wall -Wextra Run Valgrind on it and saw something strange, this simple program has memory leak, output of valgrind --leak-check=full --show-leak-kinds=all

Difference between C standard library and C POSIX library

牧云@^-^@ 提交于 2019-11-28 02:53:46
I'm a little confused by "C standard lib" and "C POSIX lib", because I found that, many header files defined in "C POSIX lib" are also part of "C standard lib". So, I assume that, "C standard lib" is a lib defined by ANSI C organization, and there are different implementation on different platforms (Win32/Unix-like), and "C POSIX lib" is just a implementation for "C standard lib" on Unix-like OSes, right? But "C POSIX lib" contains some headers not specified in "C standard lib", such as <sys/types.h> , <sys/wait.h> , and <pthread.h> . Take <pthread.h> as an example, I presume its "C standard

Which functions in the C standard library commonly encourage bad practice? [closed]

不打扰是莪最后的温柔 提交于 2019-11-28 02:50:57
This is inspired by this question and the comments on one particular answer in that I learnt that strncpy is not a very safe string handling function in C and that it pads zeros, until it reaches n , something I was unaware of. Specifically, to quote R.. strncpy does not null-terminate, and does null-pad the whole remainder of the destination buffer, which is a huge waste of time. You can work around the former by adding your own null padding, but not the latter. It was never intended for use as a "safe string handling" function, but for working with fixed-size fields in Unix directory tables

Does Objective-C have a Standard Library?

纵然是瞬间 提交于 2019-11-28 00:25:02
问题 Most somewhat modern programming languages have a standard library? It is my impression is that there isn't a decent sized standard library for Obj-C , rather that it relies mostly/all on Cocoa and that (plus people not wanting to use GNUstep) is why Obj-C is only used on macs)? Is this true/to what extent? Are there any standard obj-c collections? (note I haven't done any Obj-C programming and am not to likely to try it in the near future, I'm just curious). P.S. are there a any decent non

Is there a way to check if an istream was opened in binary mode?

萝らか妹 提交于 2019-11-27 23:31:22
I'm using an istream which could be stringstream, ifstream or a user-defined stream type and I need to know if, in the case of an ifstream, it was not opened in binary mode (so I can throw an exception). I have tried the following method: if ((_is.flags() & ios::binary) == 0) throw exception(...) but no exception is ever thrown. The test fails in this case because _is.flags() returns 0x201 and ios::binary is 0x20. Is there a way to find out if a stream was opened in text mode? flags() returns ios_base::fmtflags which is formatting flags, whereas binary is an ios_base::openmode flag. I'm not

Why does str.split not take keyword arguments?

有些话、适合烂在心里 提交于 2019-11-27 21:51:37
I came across this - in my view - strange behaviour: "a b c".split(maxsplit=1) TypeError: split() takes no keyword arguments Why does str.split() not take keyword arguments, even though it would make sense? I found this behavior both in Python2 and Python3. 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

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

∥☆過路亽.° 提交于 2019-11-27 21:16:53
Now that I've learned Swift (to a reasonable level) I'm trying to get to grips with the standard library, but in truth it's mainly ελληνικά to me! So a specific question: I have an array of strings and I can call reverse() on it. let arr = ["Mykonos", "Rhodes", "Naxos"].reverse() Now naively I thought I'd get back a type of Array from this. (Ruby for example has a similar method that you pass an array and get back an array) But arr is now actually of type ReverseRandomAccessCollection<Array<String>> which is actually a struct, which conforms to CollectionType: public struct