291 This post relates to a rapidly changing event. Just sometime ago I started getting this warning when pushing to GitHub. WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has […]
7 I am doing something very simple and straightforward, and I cannot help but suspect / wish that it could be made a bit shorter. For the sake of the example, let us suppose that I have an IEnumerable<int?> and all I want is an IEnumerable<int> yielding only the non-null values. Here is some code […]
8 Let me describe a scenario, first we have a function which returns us some sort of data which we can’t be sure about the validity of, i.e. auto random_predicate() -> bool { int v = uniform_dist(e1); // uniform distribution 1 to 100 return (v % 5); } where uniform_dist() is an appropriately seeded uniform […]
6 When a post is accessed, I need, in addition to returning the information of this posts, to return the previous one if it exists and the next one. I would like to know if there is a way to select MAX(id) and MIN(id) in a single query/select, passing a condition for each one of […]
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 […]