Tutorial by Examples: c

const auto input = "Some people, when confronted with a problem, think \"I know, I'll use regular expressions.\""s; smatch sm; cout << input << endl; // If input ends in a quotation that contains a word that begins with "reg" and another word begining...
This code takes in various brace styles and converts them to One True Brace Style: const auto input = "if (KnR)\n\tfoo();\nif (spaces) {\n foo();\n}\nif (allman)\n{\n\tfoo();\n}\nif (horstmann)\n{\tfoo();\n}\nif (pico)\n{\tfoo(); }\nif (whitesmiths)\n\t{\n\tfoo();\n\t}\n"s; cout &lt...
db.people.insert({name: 'Tom', age: 28}); Or db.people.save({name: 'Tom', age: 28}); The difference with save is that if the passed document contains an _id field, if a document already exists with that _id it will be updated instead of being added as new. Two new methods to insert documents...
Object arrays are covariant, which means that just as Integer is a subclass of Number, Integer[] is a subclass of Number[]. This may seem intuitive, but can result in surprising behavior: Integer[] integerArray = {1, 2, 3}; Number[] numberArray = integerArray; // valid Number firstElement = numb...
To be able to use JDBC you need to have the JDBC driver of your database on the class path of your application. There are multiple ways to connect to a database, but the common ways are to either use the java.sql.DriverManager, or to configure and use a database specific implementation of javax.sql...
Atomic vectors (which excludes lists and expressions, which are also vectors) are subset using the [ operator: # create an example vector v1 <- c("a", "b", "c", "d") # select the third element v1[3] ## [1] "c" The [ operator can also tak...
For each dimension of an object, the [ operator takes one argument. Vectors have one dimension and take one argument. Matrices and data frames have two dimensions and take two arguments, given as [i, j] where i is the row and j is the column. Indexing starts at 1. ## a sample matrix mat <- matr...
$a = "some string"; results in $a having the value some string. The result of an assignment expression is the value being assigned. Note that a single equal sign = is NOT for comparison! $a = 3; $b = ($a = 5); does the following: Line 1 assigns 3 to $a. Line 2 assigns 5 to $a....
The combined assignment operators are a shortcut for an operation on some variable and subsequently assigning this new value to that variable. Arithmetic: $a = 1; // basic assignment $a += 2; // read as '$a = $a + 2'; $a now is (1 + 2) => 3 $a -= 1; // $a now is (3 - 1) => 2 $a *= 2; //...
The order in which operators are evaluated is determined by the operator precedence (see also the Remarks section). In $a = 2 * 3 + 4; $a gets a value of 10 because 2 * 3 is evaluated first (multiplication has a higher precedence than addition) yielding a sub-result of 6 + 4, which equals to 10...
Left association If the preceedence of two operators is equal, the associativity determines the grouping (see also the Remarks section): $a = 5 * 3 % 2; // $a now is (5 * 3) % 2 => (15 % 2) => 1 * and % have equal precedence and left associativity. Because the multiplication occurs first ...
Simple check To check if constant is defined use the defined function. Note that this function doesn't care about constant's value, it only cares if the constant exists or not. Even if the value of the constant is null or false the function will still return true. <?php define("GOOD&quo...
Constants are created using the const statement or the define function. The convention is to use UPPERCASE letters for constant names. Define constant using explicit values const PI = 3.14; // float define("EARTH_IS_FLAT", false); // boolean const "UNKNOWN" = null; // null d...
An idiomatic technique for generating repeating code structures at compile time. An X-macro consists of two parts: the list, and the execution of the list. Example: #define LIST \ X(dog) \ X(cat) \ X(racoon) // class Animal { // public: // void say(); // }; #define...
Implementing IErrorHandler for WCF services is a great way to centralize error handling and logging. The implementation shown here should catch any unhandled exception that is thrown as a result of a call to one of your WCF services. Also shown in this example is how to return a custom object, and h...
This checks to see if the given object is null, and then throws RequiredObjectIsNullException if it is. Assert.Required(parameter, "parameter is required.");
IsNotNull This is a very simple and popular method to use to check if an item is not null. It simply checks the object that is passed in to see if it is null. Assert.IsNotNull(database, type, "Name: {0}", item); IsNotNullOrEmpty This is the same as IsNotNull above, but works on strin...
ArgumentCondition This method checks to see if the argument specified is true. It also takes in the name of the argument that is logged if the condition fails. Assert.ArgumentCondition(pageIndex >= 0, "pageIndex", "Value must be greater than or equal to zero."); ArgumentN...
CanRunApplication To check to see if the user has permission to run the given application. If not, AccessDeniedException is thrown. Assert.CanRunApplication("WebEdit"); HasAccess HasAccess will check if the given parameter is true, otherwise an AccessDeniedException will be thrown. ...
To create a PostgreSQL ArrayField, we should give ArrayField the type of data we want it to store as a field as its first argument. Since we'll be storing book ratings, we will use FloatField. from django.db import models, FloatField from django.contrib.postgres.fields import ArrayField cla...

Page 127 of 826