standard-library

Adding SequenceTypes not implemented in Swift's standard library

末鹿安然 提交于 2019-12-10 11:57:00
问题 In the standard library of Swift the + operator is only overloaded with ExtensibleCollectionType and another type which definitely conforms to SequenceType : func + <C : ExtensibleCollectionType, S : CollectionType where S.Generator.Element == C.Generator.Element>(lhs: C, rhs: S) -> C func + <C : ExtensibleCollectionType, S : SequenceType where S.Generator.Element == C.Generator.Element>(lhs: C, rhs: S) -> C func + <C : ExtensibleCollectionType, S : SequenceType where S.Generator.Element == C

What is Scalas Product.productIterator supposed to do?

拥有回忆 提交于 2019-12-10 04:06:40
问题 Can someone tell me why I am getting different results when using Tuple2[List,List] and List[List] as my Product in the code below? Specifically I would like to know why the second value of the list of lists gets wrapped in another list? scala> val a = List(1,2,3) a: List[Int] = List(1, 2, 3) scala> val b = List(4,5,6) b: List[Int] = List(4, 5, 6) scala> val c = List(a,b) c: List[List[Int]] = List(List(1, 2, 3), List(4, 5, 6)) scala> c.productIterator.foreach( println(_) ) List(1, 2, 3) List

Is it possible to minimize the console in python with the standard librairy (without extra module)?

余生长醉 提交于 2019-12-09 18:48:08
问题 I wrote a program that uses the console. Most of the time, the user must see the console informations. For a specific function from command line, I would like to run the script without the console rises. I just don't want see the window but it can be in the task bar. I know I can use extra modules (gui, win32,..) to do that but I would like to use the standard python librairy. Is it possible to do that? The program should run on Windows. (python 2.7) I specify... I know I can use pythonw.exe

O(N) Identification of Permutations

若如初见. 提交于 2019-12-09 11:55:39
问题 This answer determines if two strings are permutations by comparing their contents. If they contain the same number of each character, they are obviously permutations. This is accomplished in O(N) time. I don't like the answer though because it reinvents what is_permutation is designed to do. That said, is_permutation has a complexity of: At most O(N 2 ) applications of the predicate, or exactly N if the sequences are already equal, where N=std::distance(first1, last1) So I cannot advocate

How to workaround the inconsistent definition of numeric_limits<T>::min()?

最后都变了- 提交于 2019-12-09 05:27:48
问题 The numeric_limits traits is supposed to be a general way of obtaining various type infomation, to be able to do things like template<typename T> T min(const std::vector<T>& vect) { T val = std::numeric_limits<T>::min(); for(int i=0 ; i<vect.size() ; i++) val = max(T, vect[i]); return val; } The problem is that (at least using MS Visual Studio 2008) numeric_limits<int>::min() returns the smallest negative number, while numeric_limits<double>::min() returns the smallest positive number! Anyone

Why does OpenURI treat files under 10kb in size as StringIO?

人盡茶涼 提交于 2019-12-08 23:03:14
问题 I fetch images with open-uri from a remote website and persist them on my local server within my Ruby on Rails application. Most of the images were shown without a problem, but some images just didn't show up. After a very long debugging-session I finally found out (thanks to this blogpost) that the reason for this is that the class Buffer in the open-uri-libary treats files with less than 10kb in size as IO-objects instead of tempfiles. I managed to get around this problem by following the

Is scala sorting stable?

浪子不回头ぞ 提交于 2019-12-08 15:46:51
问题 Scala collections have sortBy method. Is that method stable? def sortList(source : List[Int]) : List[Int] = source.sortBy(_ % 2) Would that example always preserve order? 回答1: Yes, it's stable. Reference from scala source code: https://github.com/scala/scala/blob/2.11.x/src/library/scala/collection/SeqLike.scala#L627 def sortBy[B](f: A => B)(implicit ord: Ordering[B]): Repr = sorted(ord on f) /** Sorts this $coll according to an Ordering. * * The sort is stable. That is, elements that are

Strange bug in usage of abs() I encountered recently

人盡茶涼 提交于 2019-12-08 15:42:00
问题 I have C++/C mixed code which I build on a) Visual C++ 2010 Express(Free version) on Win-7 x32. b) Cygwin/Gcc environment installed on a Windows-7 Home premium edition x32. The gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) c) Ubuntu 10.04 Linux- GCC version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) I have a code as below(Its a member function for my user defined class) which computes absolute value of the passed object myhalf- myhalf::myhalfabs(myhalf a) { float tmp; tmp = abs(a.value);

Standard c++ library linking

*爱你&永不变心* 提交于 2019-12-07 12:12:24
问题 I'm trying to understand when does standard library linking to my own binary. I've written the following: #include <stdio.h> double atof(const char*); int main(){ const char * v="22"; printf("Cast result is %f", atof(v)); } It's compiling successful with g++ -c main.cpp , but when I'm linking just created object file I've an error. Error descriptio is: /tmp/ccWOPOS0.o: In function `main': main.cpp:(.text+0x19): undefined reference to `atof(char const*)' collect2: error: ld returned 1 exit

Boost's lexical_cast From double to string Precision

痞子三分冷 提交于 2019-12-07 10:29:42
问题 I'm working with a library that unfortunately uses boost::lexical_cast to convert from a double to a string . I need to be able to definitively mirror that behavior on my side, but I was hopping to do so without propagating boost . Could I be guaranteed identical behavior using to_string , sprintf , or some other function contained within the standard? 回答1: The boost code ends up here: bool shl_real_type(double val, char* begin) { using namespace std; finish = start + #if defined(_MSC_VER) &&