18 I always assumed that private inheritance simply means that a type doesn’t tell the outside that it’s inheriting from some base class. However, it seems that there are more restrictions. Consider the following minimal example: struct MyInterface {}; struct MyImpl : private MyInterface {}; struct Inherited : public MyImpl { // Error: ‘MyInterface’ not […]
16 I am building a django-react site and suddenly my docker-compose no longer builds despite any changes to requirements or image versions. My requirements.txt looks as follows: Django>=3.2.4,<4.0 djangorestframework>=3.12.4,<3.14.0 djangorestframework-simplejwt>=4.8.0,<5.3.0 psycopg2>=2.8.6,<2.9 drf-spectacular>=0.15.1,<0.30 django-allauth>0.5,<1.0 dj-rest-auth>=3.0,<4.0 The error output: => [backend internal] load .dockerignore 0.0s => => transferring context: 234B 0.0s => [backend internal] load build definition […]
22 In gatomic.c of glib there are several function declarations that look like this: gboolean (g_atomic_int_compare_and_exchange_full) (gint *atomic, gint oldval, gint newval, gint *preval) { return g_atomic_int_compare_and_exchange_full (atomic, oldval, newval, preval); } Can someone explain what this code exactly does? I’m confused by several things here: The function name g_atomic_int_compare_and_exchange_full is in parentheses. What’s the […]
25 Consider following float loop, compiled using -O3 -mavx2 -mfma for (auto i = 0; i < a.size(); ++i) { a[i] = (b[i] > c[i]) ? (b[i] * c[i]) : 0; } Clang done perfect job at vectorizing it. It uses 256-bit ymm registers and understands the difference between vblendps/vandps for the best performance possible. […]
9 I know this is a little vague question but I have tried to find an answer and I couldn’t. Can any one provide a single reasonable example on how to use the function withSizedList from vector-sized package? The context is that I am building some french deck package. I’ve decided to go into type […]
13 I have the following vectors with 0s and 1s: test1 <- c(rep(0,20),rep(1,5),rep(0,10),rep(1,15)) test1 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 […]
18 This is from: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/std/type_traits template<typename _Xp, typename _Yp> using __cond_res = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()()); … template<typename _Tp1, typename _Tp2> struct __common_reference_impl<_Tp1, _Tp2, 3, void_t<__cond_res<_Tp1, _Tp2>>> { using type = __cond_res<_Tp1, _Tp2>; }; I’m trying to figure out what _Xp(&)() is – is it a function call signature? i.e. a constructor? Doesn’t really […]
9 I am wondering if there can be a version of Ackermann function with better time complexity than the standard variation. This is not a homework and I am just curious. I know the Ackermann function doesn’t have any practical use besides as a performance benchmark, because of the deep recursion. I know the numbers […]
11 Generally, the default constructor should be the fastest way of making an empty container. That’s why I was surprised to see that it’s worse than initializing to an empty string literal: #include <string> std::string make_default() { return {}; } std::string make_empty() { return ""; } This compiles to: (clang 16, libc++) make_default(): mov rax, […]
13 For min(ctz(x), ctz(y)), we can use ctz(x | y) to gain better performance. But what about max(ctz(x), ctz(y))? ctz represents "count trailing zeros". C++ Version (Compiler Explorer) #include <algorithm> #include <bit> #include <cstdint> int32_t test2(uint64_t x, uint64_t y) { return std::max(std::countr_zero(x), std::countr_zero(y)); } Rust Version (Compiler Explorer) pub fn test2(x: u64, y: u64) -> […]