Questions tagged [standard-library]

The standard library contains core utilities provided by all implementations of the language.

The standard library contains core utilities provided by all implementations of the language.

The size and scope of the standard library varies between languages, some provide only a few basic components for such things as string handling and I/O, whereas others provide higher-level tools for a wide variety of tasks such as XML processing, networking and database access.

For questions about specific languages' standard libraries use this tag in conjunction with the tag for the language, or use the indicated tags for these languages:

677 questions
11
votes
3 answers

Which Scala methods return null instead of an Option and why?

I wonder if the standard library is completely null-free and - if not - would be interested what reasonable use-cases exist where returning null is preferable to returning some Option instance.
soc
  • 27,983
  • 20
  • 111
  • 215
11
votes
4 answers

Is the term "libc" equivalent to "C standard library"?

I sometimes hear people using the terms "libc" and "C standard library" interchangeably. I understand that "libc" is the name (or part of the names) of many popular C standard library implementations. My guess is that because of the widespread use…
pepsi
  • 6,785
  • 6
  • 42
  • 74
11
votes
1 answer

What is the result of `strtod("3ex", &end)` supposed to be? What about `sscanf`?

In my experiments this expression double d = strtod("3ex", &end); initializes d with 3.0 and places end pointer at 'e' character in the input string. This is exactly as I would expect it to behave. The 'e' character might look as a beginning of…
AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
11
votes
2 answers

Why is "lazy" a keyword rather than a standard-library type?

Scala keeps a lot of very useful constructs like Option and Try in its standard library. Why is lazy given special treatment by having its own keyword when languages such as C#, which lacks afore mentioned types, choose to implement it as a library…
megri
  • 1,019
  • 8
  • 10
11
votes
3 answers

Should I call reset() on my C++ std random distribution to clear hidden state?

I would like to wrap the random number distributions from the C++11 standard library with simple functions that take as arguments the distribution's parameters and a generator instance. For example: double normal(double mean, double sd,…
Tyler Streeter
  • 1,214
  • 12
  • 14
10
votes
20 answers

Good Idea / Bad Idea Should I Reimplement Most Of C++?

Recently, I've got a dangerous idea into my head after reading this blog post. That idea can be expressed like this: I don't need most of what the C++ standard library offers. So, why don't I implement a less general, but easier to use version? As…
fluffels
  • 4,051
  • 7
  • 35
  • 53
10
votes
1 answer

Is undefined behavior possible in safe Rust?

Is there any way to achieve undefined behavior in Rust without using unsafe? Of course, such behavior can be wrapped by a third-party library in a "safe" function so let's assume we're using only the standard one.
passing_through
  • 1,778
  • 12
  • 24
10
votes
3 answers

Optimized argmin: an effective way to find an item minimizing a function

Let us say I've got a collection of items and a score function on them: struct Item { /* some data */ }; std::vector items; double score(Item); I'd like to find the item from that collection whose score is the lowest. An easy way to write…
YSC
  • 38,212
  • 9
  • 96
  • 149
10
votes
4 answers

What is the logic behind Arrays.copyOfRange(byte[], int, int) strange behavior?

Can anyone explain me the logic behind strange behavior of Arrays.copyOfRange(byte[], int, int))? I can illustrate what I mean with simple example: byte[] bytes = new byte[] {1, 1, 1}; Arrays.copyOfRange(bytes, 3, 4); // Returns single element (0)…
Ivan Sharamet
  • 317
  • 4
  • 15
10
votes
3 answers

Are all functions in the c++ standard library required have external linkage?

So I've got an app which compiles fine on windows, linux and a few variations of unix. I recently decided to port it to OSX when I ran into a snag. I have a template which looks like this: template int safe_ctype(unsigned char c) {…
Evan Teran
  • 87,561
  • 32
  • 179
  • 238
10
votes
1 answer

Would it be legal to implement overloads of std::sort with radix sort?

For applicable data types a good radix sort can beat the pants off comparison sorts by a wide margin but std::sort is usually implemented as introsort. Is there a reason to not use radix sort to implement std::sort? Radix sort doesn't fully suffice…
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
10
votes
4 answers

C++ Do I have to include standard libraries for every source file?

I'm a bit confused at the moment because I'm planning to include multiple source and header files for the first time in one of my projects. So I'm wondering if this would be the right approach? Do I have to include the string header in every source…
Forivin
  • 14,780
  • 27
  • 106
  • 199
10
votes
5 answers

What is the role of std::forward_iterator_tag?

Upon profiling an application, I bumped into that piece of the standard library implementation shipped with gcc 4.7.1. It is include/g++-v4/bits/vector.tcc: template template void …
qdii
  • 12,505
  • 10
  • 59
  • 116
10
votes
1 answer

Comprehensive open-source test suite for the C Standard Library

I'm looking for a testsuite for the C Standard Library (mainly for the algorithms not contacting the "outer world", so strcpy(), memcmp(), itoa() & likes). I tried downloading the GCC sources, but they're very large and I have trouble finding…
akavel
  • 4,789
  • 1
  • 35
  • 66
9
votes
2 answers

Thread-safety of C standard library on OS X

Is there a definitive list of functions that are thread-safe in Mac OS X's implementation of the C standard library? There is a good answer here with regards to glibc and f*() functions specifically, but I have failed to find any such resource with…
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59