Tutorial by Examples: const

Enum constructors can be matched using pattern matching. Assume the following enum: enum Color { Red; Green; Blue; RGB(r : Int, g : Int, b : Int); } Colours with only a green channel value can be matched as follows: var color = Color.RGB(0, 127, 0); var isGreenOnly = swit...
Setters and Getters allow for an object to contain private variables which can be accessed and changed with restrictions. For example, public class Person { private String name; public String getName() { return name; } public void setName(String name) { i...
The Standard (10.4) states: Member functions can be called from a constructor (or destructor) of an abstract class; the effect of making a virtual call (10.3) to a pure virtual function directly or indirectly for the object being created (or destroyed) from such a constructor (or destructor) is u...
In C++ methods that differs only by const qualifier can be overloaded. Sometimes there may be a need of two versions of getter that return a reference to some member. Let Foo be a class, that has two methods that perform identical operations and returns a reference to an object of type Bar: class ...
Sometimes you have to deal with structures defined in terms of C data types from Perl. One such application is the creation of raw network packets, in case you want to do something fancier than what the regular socket API has to offer. This is just what pack() (and unpack() of course) is there for. ...
The behaviour of virtual functions in constructors and destructors is often confusing when first encountered. #include <iostream> using namespace std; class base { public: base() { f("base constructor"); } ~base() { f("base destructor"); } virtual co...
The auto keyword by itself represents a value type, similar to int or char. It can be modified with the const keyword and the & symbol to represent a const type or a reference type, respectively. These modifiers can be combined. In this example, s is a value type (its type will be inferred as s...
Assume you want to delegate to a class but you do not want to provide the delegated-to class in the constructor parameter. Instead, you want to construct it privately, making the constructor caller unaware of it. At first this might seem impossible because class delegation allows to delegate only to...
When we are working on a framework, if the constraints are not too complex, we'd better use Interface Builder or NSLayoutConstraint in code to make it smaller enough, instead of import Masonry or SnapKit. for example: Objective-C // 1. create views UIView *blueView = [[UIView alloc...
Constant is available both in configuration and run phases. angular.module('app',[]) .constant('endpoint', 'http://some.rest.endpoint') // define .config(function(endpoint) { // do something with endpoint // available in both config- and run phases }) .controller('MainCtrl', ...
Any attempt to modify a const object results in undefined behavior. This applies to const variables, members of const objects, and class members declared const. (However, a mutable member of a const object is not const.) Such an attempt can be made through const_cast: const int x = 123; const_cas...
A type specifier; when applied to a type, produces the const-qualified version of the type. See const keyword for details on the meaning of const. const int x = 123; x = 456; // error int& r = x; // error struct S { void f(); void g() const; }; const S s; s.f(); // error s...
To export the type and all its constructors, one must use the following syntax: module X (Person (..)) where So, for the following top-level definitions in a file called People.hs: data Person = Friend String | Foe deriving (Show, Eq, Ord) isFoe Foe = True isFoe _ = False This module d...
This does not cover allocators. struct A {}; struct B { B()=default; B(B const&)=default; B(int){}; }; struct C { C()=delete; C(int) {}; C(C const&)=default; }; struct D { D( std::initializer_list<int> ) {}; D(D const&)=default; D()=default; }; std::variant<A,B> var_ab...
R provides two additional looping constructs, while and repeat, which are typically used in situations where the number of iterations required is indeterminate. The while loop The general form of a while loop is as follows, while (condition) { ## do something ## in loop body } whe...
A conversion that involves calling an explicit constructor or conversion function can't be done implicitly. We can request that the conversion be done explicitly using static_cast. The meaning is the same as that of a direct initialization, except that the result is a temporary. class C { std:...
Shall the property value's assignment be executed before or after the class' constructor? public class TestClass { public int TestProperty { get; set; } = 2; public TestClass() { if (TestProperty == 1) { Console.WriteLine("Shall this be e...
CREATE TYPE MyUniqueNamesType as TABLE ( FirstName varchar(10), LastName varchar(10), UNIQUE (FirstName,LastName) ) Note: constraints in user defined table types can not be named.
Use parentheses and commas to create tuples. Use one comma to create a pair. (1, 2) Use more commas to create tuples with more components. (1, 2, 3) (1, 2, 3, 4) Note that it is also possible to declare tuples using in their unsugared form. (,) 1 2 -- equivalent to (1,2) (,,) 1 2 3 ...
Foreign keys enables you to define relationship between two tables. One (parent) table need to have primary key that uniquely identifies rows in the table. Other (child) table can have value of the primary key from the parent in one of the columns. FOREIGN KEY REFERENCES constraint ensures that valu...

Page 9 of 13