Get a std::move on

Move semantics in C++

  • You cannot move from a const thing: not allowed to mutate
  • Auto-generated constructors do not have strong exception guarantees
  • Adding a custom empty destructor prevents the move constructors being generated automatically
  • Fundamental types are copied when moved as they don’t handle resources
  • Move is used when returning from a function or we make a variable an rvalue with std::move
  • && modifier indicates parameter is an object that we intend to move from instead of copying

What does it all mean?

Means Mean: the average value of a data set Median: the middle of a data set, the number that splits a data set in two; requires sorting; median of an even number of elements is the mean of the middle two elements Mode: value in a data set that occurs most often; if a data set has unique numbers there is no mode; if there are equal numbers of some elements there are multiple modes Random variables Discrete: finite numbers of values Continuous: infinite number of values Probability density functions P(|Y - 2| < . [Read More]

GRASP

General Responsibility Assignment Software Principles

  1. Information expert: put the responsibility of handling inputs on the class that owns the inputs (coupling, encapsulation)
  2. Creator
  3. Low coupling
  4. Protected variations
  5. Indirection: compare with Adapter pattern
  6. Polymorphism: compare with Strategy pattern
  7. High cohesion: focus classes around one responsibility; compare with SOLID
  8. Pure fabrication: compare with Facade pattern
  9. Controller: an example of previous

References

Sorting

#include <iostream>#include <ranges>#include <vector>#include <list>#include <algorithm>#include <random>#include <iterator> int main() { const auto printy = [](const auto& v) { std::cout << "\n"; std::ranges::copy(v, std::ostream_iterator<int>(std::cout, ",\n")); }; // Make container of random values std::vector<int> v(4); std::ranges::for_each(v, [](auto &x){ x = std::rand(); }); printy(v); // Sort it std::ranges::sort(v); printy(v); // Sort it the other way std::ranges::sort(v, std::greater<int>()); printy(v); // List has its own sort std::list<int> l{std::cbegin(v), std::cend(v)}; l.sort(); printy(l); } https://godbolt. [Read More]

Using type traits to check all the esoteric OOP rules

#include <iostream>
#include <vector>
#include <memory>
#include <type_traits>

struct A {
    virtual ~A(){ std::cout << "~A\n"; }
    int i;
    int j;
};

struct B : A {
    ~B(){ std::cout << "~B\n"; }
};

static_assert(std::has_virtual_destructor<A>::value);
static_assert(std::has_virtual_destructor<B>::value);

int main() {
    std::vector<std::unique_ptr<struct A>> vec;

    vec.emplace_back(std::make_unique<A>());
    vec.emplace_back(std::make_unique<B>());
}

https://godbolt.org/z/KbGG1v63M

-Ogofaster

Notes from Andrei at code::dive 2015

Watch the whole lecture (recommended). Integrals Prefer 32-bit ints to other sizes 32-bits is the sweet spot as 64-bit ALU can handle two calculations 8, 16-bit computations convert to 32-bits so don’t use smaller Use small ints in arrays Prefer unsigned to signed Unsigned is faster Except when converting to floating point Most numbers are small If you find optimisations that work with small numbers, use them Floating point Double and single precision equivalent speed 80-bit extended only slightly slower But don’t mix them (because conversions) Ints to float point cheap Floating point to any integral is expensive Strength reduction Use minimum strength operations when optimising as the stronger ones are more costly. [Read More]

Virtual insanity...

Uses of the "virtual" keyword in C++

Virtual functions are used to achieve runtime polymorphism – https://www.educba.com/virtual-keyword-in-c-plus-plus/ Uses of the virtual keyword See https://en.cppreference.com/w/cpp/keyword/virtual Related keywords: override, final virtual function specifier The virtual specifier specifies that a non-static member function is virtual and supports dynamic dispatch. It may only appear in the decl-specifier-seq of the initial declaration of a non-static member function (i.e., when it is declared in the class definition). Virtual functions are member functions whose behavior can be overridden in derived classes. [Read More]

Money guys

Top-10 money facts

Discipline > Margin of saving money > time Deferred gratification Avoid debt 60% of Americans cannot come up with $1000 for an emergency 47% of Americans carry a credit card balance New cars lose 50% of their value in the first four years Save 20-25% of gross monthly income (10% is not enough now) Only 25% or Americans work in their field of study References https://www. [Read More]

Apache Guacamole

Installation and configuration

sudo apt install --yes software-properties-common
sudo add-apt-repository ppa:guacamole/stable
sudo apt install --yes guacamole-tomcat

sudo systemctl enable guacd
sudo systemctl start guacd

sudo ln -s /var/lib/guacamole/guacamole.war /var/lib/tomcat8/webapps
sudo ln -s /etc/guacamole/guacamole.properties /usr/share/tomcat8/.guacamole

sudo /etc/init.d/tomcat8 restart
sudo /etc/init.d/guacd start

Linear time code

You're SMPTE the best

SMPTE - Society of Motion Picture and Television Engineers HOURS:MINUTES:SECONDS:FRAMES timecode and frame rate are not the same thing genlock - generator locking The solution to this problem is drop-frame timecode, which is sort of like leap year for timecode. At 29.97 fps, every minute (except minutes divisible by ten), you skip counting the first two frames. You know you’re looking at drop frame timecode because the colon between minutes and frames is usually replaced by a semicolon. [Read More]