Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
58 views

Consider the following OpenCL code in which each element in a vector-type variable gets its value via array lookup: float* tbl = get_data(); int4 offsets = get_offsets(); float4 my_elements = { ...
einpoklum's user avatar
  • 137k
34 votes
2 answers
4k views

I am starting to learn Rust. In a lot of examples I have come across so far, I have noticed that functions are often implemented to return variables by value even if they are of a complex data type ...
fritut08's user avatar
  • 487
0 votes
1 answer
33 views

OpenCL C supports "vector data types" - a fixed number of scalar types which may be operated on together, as though they were a single scalar, mostly: we can apply arithmetic and logic ...
einpoklum's user avatar
  • 137k
5 votes
0 answers
250 views

In this earlier SO question: What is a smart pointer and when should I use one? Ten years ago, I gave a relative simple answer and got a bunch of upvotes. One paragraph in my answer reads: Use std::...
einpoklum's user avatar
  • 137k
-5 votes
1 answer
80 views

I'm working on some JS code (which will run within Thunderbird, but that's not the main point). This code is kind of old, and does asynchronous work using setTimeout(); I want to transition it to ...
einpoklum's user avatar
  • 137k
0 votes
2 answers
54 views

Please note that the example we'll be looking at is purelly for illustration purposes. If you would like to answer using a different example that's ok, as we're trying to get to an idiomatic way of ...
Doodloo's user avatar
  • 919
-3 votes
3 answers
222 views

I like C++11's std::chrono facilities, which let me work with: time points clocks durations (= differences between time points) but I occasionally need to work with time intervals, i.e. not just the ...
einpoklum's user avatar
  • 137k
-1 votes
1 answer
28 views

In a C source file of mine, I need to choose between including <linux/uuid.h> and <uuid/uuid.h> (depending on what's available on the file system - it's typically/always just one and not ...
einpoklum's user avatar
  • 137k
1 vote
1 answer
68 views

I'm editing some Python code containing the line: arr = (c_double * len(self.static_mapped[0, :]))(*self.static_mapped[0, :]) where field self.static_mapped is created using numpy.zeros and where ...
COTO's user avatar
  • 193
8 votes
6 answers
2k views

In Javascript, if I have a potentially null object obj, which, if not null, will have a field x - I can write obj?.x. This is called "optional chaining" or "safe navigation": If ...
einpoklum's user avatar
  • 137k
1 vote
1 answer
160 views

C++ has 'accumulator' operations for arithmetic (+,-,*,/) , and for bitwise operations AND and OR - but not for logical operations. Now, in our code, we sometimes need to conjunct many boolean values -...
einpoklum's user avatar
  • 137k
1 vote
2 answers
146 views

I have a CSV file with multiple categorical columns, but most of these columns contain messy data due to typing mistakes (e.g., 'spciulated', 'SPICULATED', etc. for the category 'spiculated' of the ...
Alek Fröhlich's user avatar
10 votes
4 answers
867 views

Suppose I have a function T foo(size_t i). What would be an elegant and succinct way of constructing an object arr, of type std::array<T, N>, so that we have arr[i] == foo(i)? If possible, I ...
einpoklum's user avatar
  • 137k
2 votes
8 answers
543 views

Motivation With C++ having gotten optional's (in C++17), it is now common to want to write the equivalent of: If a condition holds, initialize my variable with some expression; and if the condition ...
einpoklum's user avatar
  • 137k
0 votes
1 answer
107 views

Suppose that I have the following design implemented in an OO language (e.g. Python). I know that the OO way is a bit unnatural and sometimes not preferred when using TypeScript. So what would be the ...
zzheng's user avatar
  • 898
0 votes
1 answer
52 views

Suppose I have a Ruby script like the following to generate YAML describing a list of services: require 'yaml' environment_slug = ENV.fetch('CI_ENVIRONMENT_SLUG') YAML.dump([ { 'name' => '...
Manuel Jacob's user avatar
  • 2,014
1 vote
1 answer
120 views

I am writing a base class that provides a public update() method. When someone derives from this base class, they must implement a pure virtual method that controls a tiny bit of the behavior of this ...
Taylor's user avatar
  • 2,157
1 vote
1 answer
458 views

Suppose you have a Card component that takes content for the header, body and footer. One way to design it would be for consumers to use it like this: <Card header="foo" body="...
Adam Zerner's user avatar
  • 19.6k
0 votes
1 answer
76 views

Title pretty much covers it - I need some help understanding a couple of SCILAB idioms (Ultimate goal: convert some SCILAB code into Python) Until today, I'd never heard of, let alone seen, SCILAB or ...
user avatar
1 vote
0 answers
108 views

I have a for loop where the first iteration is a special case. The only difference is the type of one variable even though they both implement the same traits. I want to know if and how I can make it ...
Nic's user avatar
  • 117
0 votes
3 answers
100 views

struct S { foo: i32, // ... other fields } fn f(s: S) { // transform foo let new_foo = biz_logic(s.foo); // from now on, the code should read `new_foo` whenever it needs `s.foo`, ...
Incömplete's user avatar
1 vote
1 answer
80 views

What is the most common/idiomatic way to define partial functions in Perl, that is functions that are not defined on all inputs. For example, in Haskell we have safeHead :: [a] -> Maybe a safeHead [...
user avatar
9 votes
2 answers
3k views

Suppose I am writing a function that takes a bunch of strings and filters out the "bad" ones. The function then returns some strings, but there is a chance that all the strings are filtered ...
Jim's user avatar
  • 4,321
1 vote
0 answers
133 views

Context and description of the encountered problem Currently I'm learning the Rust Programming Language and last weekend I found myself implementing a generic n-Ary weighted tree data structure whose ...
JosRs's user avatar
  • 11
3 votes
2 answers
261 views

package main import "fmt" func main() { a := 1 b := 2 fmt.Printf("Before Swap: %v %v\n", a, b) a, b = b, a fmt.Printf(" After Swap: %v %v\n", a, b) ...
xmllmx's user avatar
  • 44.6k

1
2 3 4 5
25