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
13
votes
4 answers

Python negate boolean function

A python boolean function can easily be negated with lambda functions, but it's a bit verbose and hard to read for something so basic, for example: def is_even(n): return n % 2 == 0 odds_under_50 = filter(lambda x: not is_even(x),…
Vaelus
  • 1,065
  • 10
  • 27
13
votes
3 answers

How to embed Python3 with the standard library

I am attempting to embed Python in an (ultimately multiplatform) C++ app. It's important that my app contains its own Python implementation (in the same way that blender does), so that it is entirely self-contained. (Else it becomes a configuration…
P i
  • 29,020
  • 36
  • 159
  • 267
13
votes
2 answers

Java HashMap put() implementation. Why not check references first?

java.util.HashMap has an implementation of the put method, which has the following code inside it : if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { V oldValue = e.value; e.value = value; e.recordAccess(this); return…
Ace McCloud
  • 701
  • 1
  • 5
  • 16
13
votes
1 answer

How does printf work internally?

I am curious as to how printf works internally within Linux. I don't understand how it writes data to STDOUT. After a bit of searching for the internals, I downloaded glibc and took a look at the source code: __printf (const char *format, ...) { …
sdasdadas
  • 23,917
  • 20
  • 63
  • 148
13
votes
5 answers

Reading a text file backwards in C

What's the best way to read a file backwards in C? I know at first you may be thinking that this is no use whatsoever, but most logs etc. append the most recent data at the end of the file. I want to read in text from the file backwards, buffering…
Joshun
  • 248
  • 1
  • 5
  • 11
13
votes
3 answers

C++: Is all of "std" cross platform?

I keep trying different search terms for this question and I'm just finding noise on both Google and stackoverflow. If I write code using C++'s standard library (std), is it all basically guaranteed to compile for Windows, Mac, and Linux (and…
Jonathan
  • 752
  • 1
  • 9
  • 19
13
votes
2 answers

Zero inner product when using std::inner_product

The C++ program below should return a stricly positive value. However, it returns 0. What happens ? I suspect an int-double conversion, but I can't figure out why and how. #include #include #include using namespace…
Klaus
  • 1,241
  • 4
  • 14
  • 31
12
votes
2 answers

How to get current unixtime on Kotlin standard library (multiplatform)

I have a Kotlin multiplatform project, and I would like to get the current unixtime in the shared code. How do you do that in the Kotlin standard library?
Daniele B
  • 19,801
  • 29
  • 115
  • 173
12
votes
3 answers

Why std::size() is not a member of std in gcc 8.2.0

I'm trying to teach myself some C++17. Why is the compiler throwing an error for the below code snippet? #include #include #include int main() { std::vector v = { 3, 1, 4 }; std::cout << std::size(v) <<…
thumala manish
  • 198
  • 1
  • 10
12
votes
1 answer

What's the difference between Jane Street's ‘Base’, ‘Core’ and 'Core_kernel'?

I'm new to OCaml, and I it's often suggested that I use Jane Street's standard-library instead of the one that ships with the compiler. However, there seem to even be several of those, and I don't know which I should be using: Base, Core, and…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
12
votes
1 answer

Is scala sorting stable?

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?
ayvango
  • 5,867
  • 3
  • 34
  • 73
12
votes
3 answers

C++ fstream << and >> operators with binary data

I've always read and been told that when dealing with binary files that one should use read() and write() as opposed to the << and >> operators as they are meant for use with formatted data. I've also read that it is possible to use them, but it is…
RC.
  • 27,409
  • 9
  • 73
  • 93
11
votes
3 answers

How library functions in Haskell are implemented

I'm just starting to learn Haskell and would find it very helpful to see how Haskell functions are implemented. I've been able to find the Standard Prelude on different question, but I'm now interested in Data.List. Is there any way to find the…
11
votes
5 answers

where is stdin defined in c standard library?

I found this line in stdio.h : extern struct _IO_FILE *stdin; Based on this 'extern' keyword, i assume this is just a declaration. I wonder where is stdin defined and initialized?
user188276
11
votes
4 answers

How to simulate the nonexistent find_first_not_of function?

The std::basic_string class template has member functions find_first_of and find_first_not_of. The header, however, contains only a generic find_first_of. Question1: Is the absence of std::find_first_not_of(Iter1 first1, Iter1 last1,…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434