stdlib

binary_search, find_if and <functional>

std::find_if takes a predicate in one of it's overloaded function. Binders make it possible to write EqualityComparators for user-defined types and use them either for dynamic comparison or static comparison. In contrast the binary search functions of the standard library take a comparator and a const T& to the value that should be used...

Isn't the C++ standard library backward-compatible?

Hi. I'm working on a 64-bit Linux system, trying to build some code that depends on third-party libraries for which I have binaries. During linking, I get a stream of undefined reference errors for one of the libraries, indicating that the linker couldn't resolve references to standard C++ functions/classes, e.g.: librxio.a(EphReader...

Does gcc's STL support rvalue references now?

I know Visual Studio 2010's standard library has been rewritten to support rvalue references, which boosts its performance considerably. Does the standard library implementation of gcc 4.4 (and above) support rvalue references? ...

What's the difference between cstdlib and stdlib.h?

When writing C++ code is there any difference between: #include <cstdlib> and #include <stdlib.h> other than the former being mostly contained within the std:: namespace? Is there any reason other than coding standards and style to use one over the other? ...

How to pass parameters with spaces via cstdlib system

Hi, I have this windows console app which takes a file, do some calculations, and then writes the output to a specified file. The input is specified in "app.exe -input fullfilename" format. I need to call this application from my C++ program, but I have a problem with spaces in paths to files. When I call the app directly from cmd.exe b...

Adding extensions to a stdlib class in a ruby on rails project

Hey, where would I place additions to stdlib classes in a rails project? Let's say something like: class Date def foo 'foo' end end I thought about the initializer folder but it somehow felt wrong. Ideas? ...

Why do ZeroMemory, etc. exist when there are memset, etc. already?

Why does ZeroMemory, and similar calls exist in the Windows API when there are memset and related calls in the C standard library already? Which ones should I call? I can guess the answer is "depends". On what? ...

Why float "division-by-zero" exception wasn't caught in a function even handler was set?

I've tried to learn the signal handling in C, when found strange behaviour. When x /= y; executed in the context of the main function the signal handler works. But when the same executed in some function (bad_func) handler is ignored however signal handler for SIGFPE is already set. Q: Why SIGFPE wasn't caught in a function by my globa...

including <stdlib.h> causes segmentation fault

I am writing a program to read info from a text file and I had everything working. The problem is that I am trying to add the functionality to calculate the mean of some of fields and have to convert the strings to doubles. I noticed that atof would work in some cases but would return -1 for the most part. i then realized that I didn'...

stdlib and colored output in C

I am making a simple application which requires colored output. How can I make my output colored like emacs and bash do? I don't care about Windows, as my application is only for UNIX systems. Thanks. ...

Is stdlib's qsort recursive?

I've read that qsort is just a generic sort, with no promises about implementation. I don't know about how libraries vary from platform to plaform, but assuming the Mac OS X and Linux implementations are broadly similar, are the qsort implementations recursive and/or require a lot of stack? I have a large array (hundreds of thousands of...

Deriving from std::back_insert_iterator ?

I want to derive from std::back_insert_iterator to create a kind of filter for a string type, say back_xml_insert_iterator, that will examine the characters passed through it looking for characters that can not be emitted "naked" into an XML stream, e.g., '"', '&', '<', '>', and '\'', and will on-the-fly insert their character entity ref...

C read file line by line

I wrote this function to read a line from a file: const char *readLine(FILE *file) { if (file == NULL) { printf("Error: file pointer is null."); exit(1); } int maximumLineLength = 128; char *lineBuffer = (char *)malloc(sizeof(char) * maximumLineLength); if (lineBuffer == NULL) { printf("Err...

Does stdlib's rand() always give the same sequence?

I quite like being able to generate the same set of pseudo-random data repeatedly, especially with tweaking experimental code. Through observation I would say that rand() seems to give the same sequence of numbers each time*. Is it guaranteed to do this for repeated executions on the same machine / for different machines / for different...

Why does the standard library have find and find_if?

Couldn't find_if just be an overload of find? That's how std::binary_search and friends do it... ...

std::string and its automatic memory resizing

I'm pretty new to C++, but I know you can't just use memory willy nilly like the std::string class seems to let you do. For instance: std::string f = "asdf"; f += "fdsa"; How does the string class handle getting larger and smaller? I assume it allocates a default amount of memory and if it needs more, it news a larger block of memory ...

Is there "magic" in the STL?

Let me start with explaining what I mean with "magic". I will use two examples from Java: Every class inherits (directly or indirectly) the Object class. Operator overloading is not supported by Java but the + operator is defined for String objects. This means that it is impossible to make an implementation of the Object and String c...

Is there a way to get an extern variable (or function) by name

I thought I read about a C standard library function recently that was able to return a pointer to any extern variable whose name was passed to it as a const char *. I think that it works via linker symbols, if that helps. ...

Count of parameters in a parameter pack? Is there a C++0x std lib function for this?

I was just wondering if there was anything in the C++0x std lib already available to count the number of parameters in a parameter pack? I'd like to get rid of the field_count in the code below. I know I can build my own counter, but it just seems like this would be an obvious thing to include in the C++0x std lib, and I wanted to be s...

Implementing atomic<T>::store

I'm attempting to implement the atomic library from the C++0x draft. Specifically, I'm implementing §29.6/8, the store method: template <typename T> void atomic<T>::store(T pDesired, memory_order pOrder = memory_order_seq_cst); The requirement states: The order argument shall not be memory_order_consume, memory_order_acquire, nor...