Questions tagged [standard-library]

22 questions
57
votes
5 answers

Why do all functions take only ranges, not containers?

There are many useful functions in , but all of them operate on "sequences" - pairs of iterators. E.g., if I have a container and like to run std::accumulate on it, I need to write: std::vector myContainer = ...; int sum =…
lethal-guitar
  • 2,065
  • 2
  • 16
  • 19
32
votes
10 answers

Why are standard libraries not programming language primitives?

I was thinking why are there (in all programming languages I have learned, such as C++, Java, Python) standard libraries like stdlib, instead of having similar "functions" being a primitive of the language itself.
user327143
17
votes
3 answers

Why isn't there a typeclass for functions?

In a learning problem I've been messing around with, I realised I needed a typeclass for functions with operations for applying, composing etc. Reasons... It can be convenient to treat a representation of a function as if it were the function…
user8709
10
votes
4 answers

What language should I use for making a cross platform library?

I want to build a SyncML parsing library (no UI) which should be able to build up messages based on information provided by the host application, fed in by the library's methods. Also, the library should to be able to do callbacks to methods in the…
Alex
  • 587
  • 1
  • 5
  • 12
8
votes
3 answers

Why would an interface override methods of the interface(s) it extends in Java 7?

I was looking at Map and SortedMap documentation from Java 7 and I have realized that SortedMap, which extends Map overrides entrySet(), keySet() and values(). AFAIK, interfaces cannot implement a method in Java prior to Java 8. So what was the…
Utku
  • 1,922
  • 4
  • 17
  • 19
6
votes
4 answers

What was the original purpose of C strncpy() function?

C standard library has strncpy function, declared as: char *strncpy(char *dest, const char *src, size_t n); It's a strange beast, as it fills n bytes of memory pointed to by dest. It does this by first copying from string src as much as it can…
hyde
  • 3,744
  • 4
  • 25
  • 35
3
votes
2 answers

Why does Java's getSystemResourceAsStream silently consume IOExceptions?

While trying to debug a weird issue where I knew an exception should have been thrown but was not, I found the following in the Java standard library's java.lang.ClassLoader class: /** * Open for reading, a resource of the specified name from the…
3
votes
1 answer

When was STL formally introduced into C++ standard?

I fail to infer the exact point of historical introduction of STL into actual C++ standard library from the wikipedia article: https://en.wikipedia.org/wiki/Standard_Template_Library It appears to me that C++11 was somehow significant for this STL,…
3
votes
4 answers

Equivalent of C library functions

In C, almost everything requires a function. What nags me is that I don't know exactly what's going on. If there was no msvcrt.dll file, my C programs would all break because that's where all the standard library functions are. I would like to know…
Garhoogin
  • 33
  • 4
3
votes
1 answer

Does Java's Object.wait() really achieve nanosecond accuracy?

I was checking out the Java 8 standard library source code just out of curiosity, and found this in java/lang/Object.java. There are three methods named wait: public final native void wait(long timeout): This is the core of all wait methods, which…
sampathsris
  • 565
  • 5
  • 17
3
votes
2 answers

Languages with graph data structures and algorithms in standard library

I am trying to improve my knowledge and ability with graphs and graph algorithms and have noticed something curious: as far as I can tell no "mainstream" language contains support for graphs in its standard library. Trees yes, graphs no. The only…
Evicatos
  • 662
  • 6
  • 12
2
votes
1 answer

Why did C++11 add find_if() instead of overloading find()?

Why did c++11 add a separate find_if() instead of simply overloading the existing find()? Wouldn't overloading the function be sufficient?
2
votes
1 answer

How to optimize reusing a large std::unordered_map as a temporary in a frequently called function?

Simplified question with a working example: I want to reuse a std::unordered_map (let's call it umap) multiple times, similar to the following dummy code (which does not do anything meaningful). How can I make this code run faster? #include…
Abaris
  • 31
  • 1
  • 5
2
votes
2 answers

Why do we have to include multiple header files for a single library (the C standard library)?

I am not sure why there are so many header file for the C standard library (stdio.h, stdlib.h, math.h). How do these header files point to the same library? I guess I am a little bit confused about what actually is a library. Where does it exist?…
yoyo_fun
  • 2,267
  • 3
  • 17
  • 22
2
votes
2 answers

Is there a stricter strtoull() in any ubiquitous C library?

I want a function that will interpret a string as a strictly unsigned integer, failing when the string overflows, represents a negative number, or does not represent a number. strtoull() does set errno to ERANGE on overflow or EINVAL for a string…
ShadSterling
  • 163
  • 5
1
2