Question: How long will it take me to understand and appreciate programming as [I?] perceive you do?
One minute response: That depends on your abilities and your habits (and what you think my abilities are).
Question: Finding duplicates of an unsorted vector<mytype>? What does count_if()
and for_each_if()
return with a predicate?
One minute response: If a sequence is unordered, it will generally take O(n2) time to find duplicates; if you know something special about the sequence (such as maximum and minimum bounds on values in the sequence), it can take O(n) time (with probably non-constant space).
count_if()
returns the number of values in the range for which the predicate returned true. There is no for_each_if()
; for_each()
returns the unary function passed in.)
Question: For ostream and istream, are the iterators the same as any other iterator? I mean, can I define an iterator for a ostream as std::ostream<type>::iterator itr_stream
?
One minute response: The stream iterators are themselves classes, so you declare them directly: std::ostream<type> itr_stream
.
Question: In C++ do we have any tool that analyzes the performance of the program. I suppose, in Java there is a tool that given the [?] of a program, like how long it takes?
One minute response: There are plenty of dynamic performance analyzers available; see, for example, the gprof man page. Static analyzers, on the other hand, are a different story given C++'s overwhelming syntactic and semantic complexity. Commercial analyzers are wickedly expensive; I've never used them, so I can't say if they're worth it. The free static analyzers I've had experience with are useless.
Question: We use generic algorithms (GA) to write less, simplified code. If there is a situation where using loops give much simplified code then using GA can we use loop instead?
One minute response: Of course; the objective is to design and implement the best code possible. But you better make sure that using loops really are better than using an equivalent generic algorithm.
This page last modified on 16 July 2003.