standard-library

How can I use functools.partial on multiple methods on an object, and freeze parameters out of order?

守給你的承諾、 提交于 2019-12-24 01:38:19
问题 I find functools.partial to be extremely useful, but I would like to be able to freeze arguments out of order (the argument you want to freeze is not always the first one) and I'd like to be able to apply it to several methods on a class at once, to make a proxy object that has the same methods as the underlying object except with some of its methods parameters being frozen (think of it as generalizing partial to apply to classes). And I'd prefer to do this without editing the original object

Restriction of C standard I/O and why we can't use C standard I/O with sockets

蹲街弑〆低调 提交于 2019-12-23 19:35:58
问题 I am reading CSAPP recently. In section 10.9, it said that standard I/O should not be used with socket because of the reasons as follows: (1) The restrictions of standard I/O Restriction 1: Input functions following output functions. An input function cannot follow an output function without an intervening call to fflush, fseek, fsetpos, or rewind. The fflush function empties the buffer associated with a stream. The latter three functions use the Unix I/O lseek function to reset the current

how to use standard library with C++ modules? (eg: `import std.io`)

对着背影说爱祢 提交于 2019-12-22 06:06:13
问题 The basic example given in How do I use C++ modules in Clang? works for me but doesn't import the standard library (eg via import std.stdio; ); after going over http://clang.llvm.org/docs/Modules.html it wasn't clear how to use the standard library in a C++ module, eg: // foo.cppm: export module foo; // works: #include <stdio.h> // none of these work: import std.stdio; import std.io; import std; export void test_foo(){ printf("hello world\n"); } this gives an error: clang++ -std=c++17

How do I use C++ STL containers in My iPhone App?

喜你入骨 提交于 2019-12-22 04:19:34
问题 I'd like to use an STL set in my iPhone app (which is written in Objective-C in XCode). How do I include set and/or use the standard namespace? In C++ I'd do this: #include<set> using namespace std; // use the set<T> somewhere down here... How can I do this in Objective-C? 回答1: Just rename your source file so it ends in .mm and it should trigger the Objective-C++ front-end; you can then mix Objective-C and C++ in it. More information here. 回答2: STL is not directly supported in objective-C.

Does Rust have Collection traits?

▼魔方 西西 提交于 2019-12-22 03:24:28
问题 I'd like to write a library that's a thin wrapper around some of the functionality in BTreeMap. I'd prefer not to tightly couple it to that particular data structure though. Strictly speaking, I only need a subset of its functionality, something along the lines of the NavigableMap interface in Java. I was hoping to find an analogous trait I could use. I seem to recall that at some point there were traits like Map and MutableMap in the standard library, but they seem to be absent now. Is there

Are there actual systems where difftime accounts for leap seconds?

守給你的承諾、 提交于 2019-12-21 20:14:55
问题 The C standard (ISO/IEC 9899) states: 7.2x.2.2 The difftime function Synopsis #include <time.h> double difftime(time_t time1, time_t time0); Description The difftime function computes the difference between two calendar times: time1 - time0 . Returns The difftime function returns the difference expressed in seconds as a double . This leaves it ambiguous (I guess, intentionally) if the result accounts for leap seconds or not. The difference (26 seconds when comparing from 1970 to July 2015)

Why are many Python built-in/standard library functions actually classes

。_饼干妹妹 提交于 2019-12-21 13:03:39
问题 Many Python builtin "functions" are actually classes, although they also have a straightforward function implementation. Even very simple ones, such as itertools.repeat . What is the motivation for this? It seems like over-engineering to me. Edit: I am not asking about the purpose of itertools.repeat or any other particular function. It was just an example of a very simple function with a very simple possible impementation: def repeat(x): while True: yield x But itertools.repeat is not

trim is not part of the standard c/c++ library?

无人久伴 提交于 2019-12-20 17:37:59
问题 Is it me or are there no standard trim functions in the c or c++ library? is there any single function that acts as a trim? If not can anyone tell me Why trim is not part of the standard library? (i know trim is in boost) My trim code is std::string trim(const std::string &str) { size_t s = str.find_first_not_of(" \n\r\t"); size_t e = str.find_last_not_of (" \n\r\t"); if(( string::npos == s) || ( string::npos == e)) return ""; else return str.substr(s, e-s+1); } test: cout << trim(" \n\r\r\n

Does C or C++ have a standard regex library?

♀尐吖头ヾ 提交于 2019-12-20 10:28:29
问题 Does it? If yes, where can I get the documentation for it... if not, then which would be the best alternative? 回答1: C++11 now finally does have a standard regex library - std::regex. If you do not have access to a C++11 implementation, a good alternative could be boost regex. It isn't completely equivalent to std::regex (e.g. the "empty()" method is not in the std::regex) but it's a very mature regex implementation for C++ none the less. 回答2: Under UNIX-like systems you can use POSIX regex

Changing Java PriorityQueue to a Max PQ [duplicate]

安稳与你 提交于 2019-12-20 10:27:30
问题 This question already has answers here : Change priorityQueue to max priorityqueue (14 answers) Closed 3 years ago . The Priority Queue implementation in the Java standard library appears to be a min Priority Queue which I found somewhat confusing. In order to turn it into a max one I created a custom comparator object. Comparator<Integer> cmp = new Comparator<Integer>() { public int compare( Integer x, Integer y ) { return y - x; } }; I was wondering if there was a more elegant solution.