6 I have a vector of strings c("YSAHEEHHYDK", "HEHISSDYAGK", "TFAHTESHISK", "ISLGEHEGGGK", "LSSGYDGTSYK", "FGTGTYAGGEK", "VGASTGYSGLK", "TASGVGGFSTK", "SYASDFGSSAK", "LYSYYSSTESK") for each string I would like to replace "Y", "S" or "T" with "pY", "pS" or "pT". But I dont want all the replacements to be in the same final string, I want each replacement to generate a […]
12 Given base class A and derived class B, A has deleted move constructor: class A { public: A() {} A(const A&) = default; A(A&&) = delete; }; class B : public A { }; In such case, the following function does not compile because of deleted move constructor: A f() { A a; return […]
8 While (re)implementing a simple constexpr map, I wrote this (godbolt): template <class key_type, class value_type, int N> class flat_map { private: struct pair { key_type key; value_type value; }; const pair elements[N]; public: consteval flat_map(const pair (&arr)[N]) noexcept : elements(arr) // works on gcc?! {} [[nodiscard]] consteval value_type operator[](const key_type key) const { for […]
14 For example: class B; class A { public: B f(); }; int main(int, char**) { A a; // no exception and error return 0; } The class A may be an incomplete type. Why can class A be instantiated in this example? I know that the program will fail to compile when the member […]
7 An example where one is overriding POD return type without const in the derived class: struct B1 { virtual const int* f(); }; struct D1 : B1 { int* f() override; }; Compilers like Clang and GCC raise a warning: invalid covariant return type for ‘virtual int* D1::f()’ When same scenario is applied but […]
11 Can someone explain the execution order of this code? struct Foo { ~Foo() { std::cout << "1"; } }; int main() { const Foo& bar = Foo(); const Foo& baz = std::move(Foo()); std::cout << "2"; } The following code prints 121. I understand why I get 1 after 2, it’s because the lifetime of […]
24 Letting them compete three times (a million pops/dels each time): from timeit import timeit for _ in range(3): t1 = timeit(‘b.pop(0)’, ‘b = bytearray(1000000)’) t2 = timeit(‘del b[0]’, ‘b = bytearray(1000000)’) print(t1 / t2) Time ratios (Try it online!): 274.6037053753368 219.38099365582403 252.08691226683823 Why is pop that much slower at doing the same thing? python […]
11 I found a weird java discrepancy while testing some timezones with the use of ZonedDateTime. I was trying to parse a date before 1970 and saw that the result changes between java versions. The offset for Netherlands in 1932 is +00:19. Does anyone know why this happens? I feel this might be related with […]
14 I’m using EAS to build my Expo app, and today I started getting this error when attempting to run an iOS build, either local or on EAS servers. I’m thinking it’s an issue with Apple servers, so I’m hoping it gets fixed soon. Output from build command: тЬФ Select platform тА║ iOS тЬФ Using […]
908 Given the following examples, why is outerScopeVar undefined in all cases? var outerScopeVar; var img = document.createElement(‘img’); img.onload = function() { outerScopeVar = this.width; }; img.src = ‘lolcat.png’; alert(outerScopeVar); var outerScopeVar; setTimeout(function() { outerScopeVar = ‘Hello Asynchronous World!’; }, 0); alert(outerScopeVar); // Example using some jQuery var outerScopeVar; $.post(‘loldog’, function(response) { outerScopeVar = response; […]