27 A common source of bugs in C or C++ is code like size_t n = // … for (unsigned int i = 0; i < n; i++) // … which can infinite-loop when the unsigned int overflows. For example, on Linux, unsigned int is 32-bit, while size_t is 64-bit, so if n = 5000000000, […]
18 A common source of bugs in C or C++ is code like size_t n = // … for (unsigned int i = 0; i < n; i++) // … which can infinite-loop when the unsigned int overflows. For example on Linux unsigned int is 32-bit, while size_t is 64-bit, so if n = 5000000000, […]
27 The following C++ code prints 11.1 then crashes. The lambda function seems to be called correctly inside the constructor, but then later, that same function no longer works! Why is this? Does the lambda have a limited lifespan? #include <functional> #include <iostream> class LambdaStore { public: LambdaStore(const std::function<void(float)>& _fn) : fn(_fn) { fn(11.1f); // […]
10 I have a dataframe as the following : COL_1 COL_2 COL_3 COL_4 COL_5 COL_6 <int> <int> <int> <int> <int> <int> 1 1 1 1 1 1 1 2 1 1 1 1 1 2 3 1 1 1 1 1 3 4 1 1 1 1 1 4 5 1 2 1 1 1 […]
8 Is the C++ code below well-formed? Will the std::string get destroyed before or after the function finishes executing? void my_function(const char*); … my_function(std::string("Something").c_str()); c++ string temporary-objects Share Improve this question Follow edited 9 hours ago Evg 25k55 gold badges3939 silver badges8383 bronze badges asked 11 hours ago BlueCannonBallBlueCannonBall 13311 silver badge33 bronze badges 4 […]
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 […]