690 questions
4
votes
1
answer
208
views
std::format formatter for volatile
This simple code:
#include <print>
int main()
{
volatile int i = 5;
std::println("{}", i);
}
Doesn't compile with any major implementation of the std library. Any particular ...
4
votes
1
answer
113
views
Are spelling variations of encoding identifiers for "setlocale" standardized or documented?
This question has to do with syntactic conventions for string encoding identifiers in locale names passed to setlocale in C, focusing on the particular example of UTF-8. My preliminary observation is ...
4
votes
3
answers
274
views
Why is std::floor not found when including <math.h> in C++23 on Android?
this seems just like a little quirk that I can fix just by including <cmath> where std::floor is used, but still this is weird and I'm wondering if anyone knows what's happening. I have a ...
1
vote
0
answers
126
views
Can `std::from_chars` not handle hexadecimal floating-point numbers?
The following program
#include <charconv>
#include <string>
#include <iostream>
int main() {
std::string s = "0X1.BC70A3D70A3D7P+6";
std::cout << "...
1
vote
2
answers
213
views
Why can std::tuple contain references?
I learned ages ago that Standard Library containers won't accept references. E.g. this simple program won't compile because of attempting to create a vector of int&:
#include <vector>
int ...
4
votes
2
answers
396
views
Why is the C++ standard library imported as a single module instead of multiple smaller modules?
If I wanted to only use std::string, for example, wouldn't importing a (theoretical) std::string module be more performant than importing the entire standard library?
Is it for ease of use, since you ...
1
vote
1
answer
102
views
Mathematical special function not found despite, supposedly, being defined in cmath
I need to use the logarithmic integral function which is defined in the cmath header. Unfortunately, I get an error: no member named 'expint' in namespace 'std' when I try to compile it. To reproduce ...
0
votes
0
answers
101
views
Vector operation modules in Python Standard Library?
I'm solving some competitive programming problems related to vectors, but I can only use modules from the standard library, I'm not sure if there is any module that defines vectors and vector ...
6
votes
1
answer
1k
views
`from typing` vs. `from collections.abc` for standard primitive type annotation?
I'm looking at the standard library documentation, and I see that from typing import Sequence is just calling collections.abc under the hood.
Now originally, there was a deprecation warning/error and ...
5
votes
1
answer
537
views
Do any Ranges view-adaptor types (from `std::views`) rely on heap allocation?
I know that at least most Ranges view types don't require any heap-allocation. For example, you can take a C array on the stack and pipe it through std::views::take(42) without causing any heap-...
-2
votes
1
answer
586
views
What's the difference between types.Implements and types.Satisfies?
What's the difference between types.Implements and types.Satisfies in golang?
I'm working on a code that inspects Go AST.
7
votes
3
answers
1k
views
How to compose functions through purely using Python's standard library?
Python's standard library is vast, and my intuition tells that there must be a way in it to accomplish this, but I just can't figure it out. This is purely for curiosity and learning purposes:
I have ...
1
vote
2
answers
135
views
Can Arrays.sort(T[] a, Comparator<? super T> c) ever throw ClassCastException if c is not null?
The javadoc for Arrays.sort(T[] a, Comparator<? super T> c) from the package java.util in the standard library for Java 20 API docs reads as follows:
public static void sort(T[] a, Comparator&...
1
vote
0
answers
66
views
How does my compiler know what printf() does? [duplicate]
Maybe this is a stupid question, but I'm new to this and trying to understand things.
Let's say I want to write a simple "Hello World" program:
// hello.c
int main() {
printf("%s\n&...
1
vote
2
answers
269
views
What is the basic type that underlies all other Swift types?
I'm currently trying to get a better understanding of Apple's open-source Swift compiler on GitHub. After using Swift for several years, I've gotten used to the philosophy of defining important types ...
1
vote
1
answer
192
views
Is there any tool to remove rvalue reference but not lvalue refrence within the standard library?
Basically I want to this:
template<typename TYPE>
struct not_rvalue_reference{
typedef std::conditional_t<std::is_rvalue_reference_v<TYPE>, std::remove_reference_t<TYPE>, TYPE&...
3
votes
1
answer
264
views
When can the standard library functions throw exceptions?
I'm having trouble understanding which functions from the standard library can throw exceptions, and if so which and when.
Some functions are noexcept, in which case ok they don't, but if I look for ...
0
votes
2
answers
319
views
Are there any rust functions for wrapping an iterator that is dependent on a reference so the wrapper contains the referent?
In this case I want to read integers from standard input such that they are separated by spaces and newline. My first attempt was similar to the following code:
fn splitter(x: String) -> impl ...
1
vote
1
answer
62
views
Rascal MPL overload library functions
It's easy to overload your own functions like so:
void testVal(loc l) {
println("LOC <l>");
}
void testVal(value v) {
println("VAL <v>");
}
such that testVal(|...
0
votes
1
answer
179
views
scala: Ordering.by vs Ordering.on
What is the difference between Ordering.by() and Ordering.on() in Scala?
(Well, one is defined in the trait and the other in the companion object, and the implementation code is also different, but ...
2
votes
1
answer
259
views
Namespaces and C++ library
Is a namespace contained in a library or a library is contained in a namespace?
How many namespaces are there in the C++ standard library ?
4
votes
3
answers
1k
views
va_list in C: Creating a function that doesn't need a argument count like 'printf'
Using the <stdarg.h> header, one can make a function that has a variable number of arguments, but:
To start using a va_list, you need to use a va_start macro that needs to know how many ...
2
votes
1
answer
485
views
Exception in Python Trace Module: "Charmap Can't Encode..."
I am using the python trace module in order to figure out why my program is exiting early.
However, there seems to be a bug with the trace module itself.
When i run py -m trace -t src/main.py > ...
0
votes
1
answer
282
views
Why does Go stdlib use a mutually exclusive lock to read context's error field?
There are a number of under-the-hood implementations of the Context interface in the Go standard library. For instance, the Background and TODO contexts are backed by the unexposed emptyCtx type which ...
0
votes
3
answers
340
views
Where can I see how OCaml’s standard library functions are implemented?
I'm interested in how List.init and other library functions are implemented in OCaml. Where can I see the implementations? I checked this official link: https://v2.ocaml.org/api/List.html and only ...
5
votes
1
answer
1k
views
How and why is Kotlin's `Map` iterable even though it is not `Iterable`?
As it was in Java, any object that is Iterable can be used in an enhanced for loop. I thought the same held true for Kotlin as well, until I discovered that kotlin.collections.Map is not Iterable at ...
0
votes
1
answer
55
views
Logging message inside except exception
I am trying to use logging when try fails. I have a for loop for converting a string of date into datetime format.
For example, converting "03/05/2021" to 2021-05-03. However, there are ...
0
votes
2
answers
377
views
Does FileInputStream incorrectly implement InputStream?
The docs for InputStream.read(bytes) say "This method blocks until input data is available, end of file is detected, or an exception is thrown."
However, java.io.FileInputStream extends java....
7
votes
1
answer
2k
views
Why will Rust integer types be deprecated soon?
I've noticed a deprecation note on the Rust std page next to u8, i8, u16 and so on:
What is going on, and what will the replacement be?
7
votes
1
answer
3k
views
Why is there no Disjoint Set (Union Find Algorithm) implemented in most mainstream programming languages' standard library?
I have found articles on how to implement a Disjoint Set (Union Find Algorithm implementation) for C++, Java, Kotlin, Python, etc.. The implementation of it is not especially difficult, although there ...
4
votes
1
answer
160
views
Why does a module type annotation in OCaml cause this code to not compile?
I am working with the Map module in OCaml. Consider the following code to create a map with ints as keys:
module Int = struct
type t = int
let compare a b = a - b
end
module IntMap = Map....
2
votes
1
answer
8k
views
Python: setting generator Polynomial in zlib.crc32
I am trying to use zlib.crc32 to compute CRC in Python.
I would like to be able to set the generator polynomial of the CRC, but I cannot find any documentation. So the question is: can this be done?
I ...
3
votes
0
answers
109
views
Does Scala use Java collections implementations under the hood?
As a part of academic project I was about to microbenchmark some Java and Kotlin collections behaviours, and compare them to each other.
Recently I found out, that under the hood Kotlin, when run on ...
3
votes
3
answers
415
views
Smart pointers with functions returning a pointer in an argument
This question was discussed a few times but all those discussions almost a decade old and there was no good solution. The question is the same.
We have smart pointers, like unique_ptr, that is great. ...
0
votes
1
answer
299
views
how to solve error ModuleNotFoundError on virtual env subdirectory?
As seen in the image below, I finished working on my project folder "click" under the main folder "my project." I didn't establish a virtual environment when I first started ...
-2
votes
1
answer
112
views
In a C program, what exactly happens under the hood if I call a function from a header file from /usr/include? [closed]
The header files of C library functions can be found under /usr/include. The actual source files, however, don't seem to be simply located anywhere in the file system.
So what exactly happens under ...
0
votes
1
answer
564
views
Why Int8.max &+ Int8.max equals to "-2"?
Following Swift Standard Library documentation, &+ discards any bits that overflow the fixed width of the integer type. I just did not get why adding two maximum values, 8-bit signed integer can ...
1
vote
1
answer
1k
views
Are there any functions like getattr/hasattr but which skip instance attributes?
Are there any functions like the built-in functions getattr and hasattr in the standard library but which skip instance attributes during attribute lookup, like the implicit lookup of special methods?
...
25
votes
1
answer
36k
views
Get Unix time in Python
In Python, I want to get the current Unix timestamp and then store the value for the long term and be handled by non-Python systems. (I am not merely trying to compute the difference between two ...
3
votes
2
answers
1k
views
Data structure like frozenset which maintains insertion order?
I need set-like data structure with these properties:
hashable
no duplicate elements
maintains order
immutable
iterable
part of standard library? want to keep it simple
What is happening:
frozenset([...
4
votes
2
answers
10k
views
CPU utilization during testing in Python?
I want to get the cpu usage during testing for my ML model (during a call to predict). Here is currently what I am doing. p is the current process:
start = p.cpu_percent(interval=1)
y_hat = clf....
0
votes
0
answers
51
views
My implementation of EqualsIgnoreCase in C is not working
I am currently attempting to program a sort of database in C.
When I create a new character for the database, it should not have the same name as any other character, case-insensitive - so, if "...
0
votes
2
answers
1k
views
How to calculate average from text file without numpy or pandas
Here is the code I used to calculate average with numpy and pandas
def calc_average_books_stock():
text_file = open('book_data_file.txt')
values = []
for index,data in df.iterrows(...
0
votes
0
answers
27
views
Overloading operator + starting from += for vector class in C++ [duplicate]
I know there are plenty of discussions about this topic, like this famous one (see sbi's answer). My goal is to overload the operator + for two vectors, starting from the operator +=, as explained in ...
19
votes
2
answers
8k
views
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?
3
votes
2
answers
2k
views
How to get Node-Entry Reference from LinkedList in java
How to get the reference to the actual Node (entry) object from LinkedList - Not the value that it holds?
Something like this :
import java.util.LinkedList;
public class Main {
public static ...
1
vote
1
answer
148
views
A Function to Test if `get-in` will Succeed
In Clojure/Script the contains? function can be used to check if a subsequent get will succeed. I believe that the Clojure version will do the test without retrieving the value. The ClojureScript ...
-2
votes
1
answer
1k
views
Python - How to create a delete function for user input?
I've been trying to create a program which allows users to view a text file's contents and delete some or all of a single entry block.
An example of the text's file contents can be seen below:
Special ...
1
vote
0
answers
127
views
I have a question about the source, 'multipelx async iterator' of Deno standard library
What is purpose of iteratorCount in the following code (from https://deno.land/[email protected]/async/mux_async_iterator.ts)?
#iteratorCount = 0
#yields = []
#throws = []
#signal = deferred()
add () {
++...
-1
votes
1
answer
619
views
How to include «pty.h» Header File on Unix / Add «pty.h» to Standard library C / C++
I would like to include pty.h which is not normally available on Unix (Not included in standard library). On the Internet, you can get the related header file content. So how do you add this header ...