Tutorial by Examples: const

Route constraints let you restrict how the parameters in the route template are matched. The general syntax is {parameter:constraint}. For example: // eg: /users/5 [Route(“users/{id:int}”] public ActionResult GetUserById(int id) { … } // eg: users/ken [Route(“users/{name}”] public ActionRes...
The where construct, available in Fortran90 onwards represents a masked do construct. The masking statement follows the same rules of the if statement, but is applied to all the elements of the given array. Using where allows operations to be carried out on an array (or multiple arrays of the same s...
ConstantExpression must be the same type of the MemberExpression. The value in this example is a string, which is converted before creating the ConstantExpression instance. private static ConstantExpression GetConstant(Type type, string value) { // Discover the type, convert it, and create Co...
Unlike var, const/let are bound to lexical scope rather than function scope. { var x = 1 // will escape the scope let y = 2 // bound to lexical scope const z = 3 // bound to lexical scope, constant } console.log(x) // 1 console.log(y) // ReferenceError: y is not defined console.log(z...
Problem statement: Find the minimum (over x, y) of the function f(x,y), subject to g(x,y)=0, where f(x,y) = 2 * x**2 + 3 * y**2 and g(x,y) = x**2 + y**2 - 4. Solution: We will solve this problem by performing the following steps: Specify the Lagrangian function for the problem Determine the K...
void parallelAddition (unsigned N, const double *A, const double *B, double *C) { unsigned i; #pragma omp parallel for shared (A,B,C,N) private(i) schedule(static) for (i = 0; i < N; ++i) { C[i] = A[i] + B[i]; } } This example adds two vector (A and B into...
Say you have a Parent class and a Child class. To construct a Child instance always requires some Parent constructor to be run at the very gebinning of the Child constructor. We can select the Parent constructor we want by explicitly calling super(...) with the appropriate arguments as our first Chi...
// Must enable the feature to use associated constants #![feature(associated_consts)] use std::mem; // Associated constants can be used to add constant attributes to types trait Foo { const ID: i32; } // All implementations of Foo must define associated constants // unless a defaul...
Using the IntDef#flag() attribute set to true, multiple constants can be combined. Using the same example in this topic: public abstract class Car { //Define the list of accepted constants @IntDef(flag=true, value={MICROCAR, CONVERTIBLE, SUPERCAR, MINIVAN, SUV}) //Tell the compi...
#include <iostream> #include <map> #include <string> using namespace std; class A { public: map<string, string> * mapOfStrings; public: A() { mapOfStrings = new map<string, string>(); } void insertEntry(string const & key, st...
Copy constructor on the other hand , is the complete opposite of the Assignment Constructor. This time, it is used to initialize an already nonexistent(or non-previously initialized) object. This means it copies all the data from the object you are assigning it to , without actually initializing the...
Ok we have briefly looked over what the copy constructor and assignment constructor are above and gave examples of each now let's see both of them in the same code. This code will be similar as above two. Let's take this : // Copy vs Assignment Constructor #include <iostream> #include <s...
In a const-correct class, all member functions which don't change logical state have this cv-qualified as const, indicating that they don't modify the object (apart from any mutable fields, which can freely be modified even in const instances); if a const cv-qualified function returns a reference, t...
In a const-correct function, all passed-by-reference parameters are marked as const unless the function directly or indirectly modifies them, preventing the programmer from inadvertently changing something they didn't mean to change. This allows the function to take both const and non-cv-qualified ...
One of the more useful things about const correctness is that it serves as a way of documenting code, providing certain guarantees to the programmer and other users. These guarantees are enforced by the compiler due to constness, with a lack of constness in turn indicating that code doesn't provide...
// Let's take an arbitrary piece of data, a 4-byte integer in this case let some_data: u32 = 14; // Create a constant raw pointer pointing to the data above let data_ptr: *const u32 = &some_data as *const u32; // Note: creating a raw pointer is totally safe but dereferencing a raw pointe...
Typescript supports costant enumerables, declared through const enum. This is usually just syntax sugar as the costant enums are inlined in compiled JavaScript. For instance the following code const enum Tristate { True, False, Unknown } var something = Tristate.True; compil...
USE [MyDatabase] CREATE MESSAGE TYPE [//initiator] VALIDATION = WELL_FORMED_XML; GO CREATE CONTRACT [//call/contract] ( [//initiator] SENT BY INITIATOR ) GO CREATE QUEUE InitiatorQueue; GO CREATE QUEUE TargetQueue; GO CREATE SERVICE InitiatorService ON QUEUE...
Example Controller action use Symfony\Component\HttpFoundation\Request; public function exampleAction(Request $request) { /* * First you need object ready for validation. * You can create new object or load it from database. * You need to add some constraints for this obj...
No matter how many problems you solve using dynamic programming(DP), it can still surprise you. But as everything else in life, practice makes you better. Keeping these in mind, we'll look at the process of constructing a solution for DP problems. Other examples on this topic will help you understan...

Page 11 of 13