1,248 questions
0
votes
1
answer
33
views
How should I cater to package users via FetchContent_MakeAvailable who don't want me to install?
I maintain a library, let's call it libfoo, using CMake as a build system generator. I've made my library usable via FetchContent_MakeAvailable() (although I dislike that interface), e.g. by prefixing ...
1
vote
1
answer
71
views
In CMake, how do I check which libc version my C compiler uses?
In a project I'm working on, I need to determine which libc is being used, for reasons.
I know that, on current Linux systems, I can usually write:
$(gcc --print-library=libc.so.6) | head -1
and get ...
5
votes
2
answers
411
views
Should I use std::rethrow_exception in my catch block, rather than directly rethrowing it?
In my code, I have something like:
try { do_stuff(); }
catch(my_exception_class& e) {
if (not can_ignore_exception(e)) {
throw e;
}
log_or_do_nothing(e);
}
A static analyzer (...
Best practices
10
votes
29
replies
8k
views
Moving from C, how can I implement a doubly linked list in C++ using C++ features?
I'm moving from C to C++ and I'm trying to avoid using C practices in C++.
It is said that raw pointers are a C feature, and that in C++ I should use smart pointers instead, yet every example I have ...
1
vote
1
answer
85
views
odin(idioma): the preferred way to compare slices
If i would compare by references i can deal with raw_data from
What is the preferred method of comparing values?
I think it's too generic to not exist in std...
// Maybe I can make `return false` on `...
0
votes
1
answer
68
views
What's the OpenCL idiom for elementwise array-lookup / gather operation with vectorized types?
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 = {
...
0
votes
0
answers
61
views
Is it legitimate (and possible) to write a CMake find module which sometimes returns an 'empty' target?
I have a project which depends on a certain library libfoo which doesn't have a CMake find module, nor does it have a CMake config file one can use. So, I'm thinking of writing a FindFoo.cmake module.
...
35
votes
2
answers
4k
views
Why is "return by value" idiomatic in Rust (as opposed to out parameters)?
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 ...
1
vote
2
answers
153
views
Simulating (as far as possible) anonymous struct declaration + dynamic initialization
In some languages, we can declare and initialize an anonymous struct - or the equivalent thereof - seamlessly. Example from ECMAScript:
function foo_in_ecmascript(x) {
let computed = {
...
0
votes
1
answer
38
views
How should I perform an elementwise cast of an OpenCL C vector value?
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 ...
2
votes
1
answer
157
views
Idiom for owning multi-dimensional arrays, after mdspan standardization?
The C++ standard library, and specifically its part involving containers and ranges, is mostly "one-dimensionally oriented" - things have a start and and end you go from start to end. If you ...
5
votes
0
answers
267
views
Am I over-encouraging people to use shared_ptr's? [closed]
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::...
0
votes
2
answers
120
views
What's the idiomatic way of assigning a nullable variable to 2 different blocks?
I thought the let and elvis operator would take care of nullable another way it seems to. In my above example, I want to check for a for being not null and returnSomethingNullable or in case a is null ...
-5
votes
1
answer
90
views
An idiom for async functions with "busy" indication and progress logging?
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 ...
3
votes
2
answers
170
views
How to instantiate a struct containing many private properties in a separate module without using a constructor function?
I want the user to be able to pass the struct along and instantiate it without a
constructor function, but not be able to modify the structure's fields without
using the setter methods provided in the ...