Tutorial by Examples

std::enable_if is a convenient utility to use boolean conditions to trigger SFINAE. It is defined as: template <bool Cond, typename Result=void> struct enable_if { }; template <typename Result> struct enable_if<true, Result> { using type = Result; }; That is, enable_...
C++11 void_t is a meta-function that maps any (number of) types to type void. The primary purpose of void_t is to facilitate writing of type traits. std::void_t will be part of C++17, but until then, it is extremely straightforward to implement: template <class...> using void_t = void; ...
C++11 One of constraining function is to use trailing decltype to specify the return type: namespace details { using std::to_string; // this one is constrained on being able to call to_string(T) template <class T> auto convert_to_string(T const& val, int ) ->...
SFINAE stands for Substitution Failure Is Not An Error. Ill-formed code that results from substituting types (or values) to instantiate a function template or a class template is not a hard compile error, it is only treated as a deduction failure. Deduction failures on instantiating function templa...
main.rs extern crate serde; extern crate serde_json; // Import this crate to derive the Serialize and Deserialize traits. #[macro_use] extern crate serde_derive; #[derive(Serialize, Deserialize, Debug)] struct Point { x: i32, y: i32, } fn main() { let point = Point { x: ...
An example document class that prints “Hello, World” to the debug console when instantiated. import flash.display.Sprite; public class Main extends Sprite { public function Main() { super(); trace("Hello, World"); } }
fn main() { let maybe_cake = Some("Chocolate cake"); let not_cake = None; // The unwrap method retrieves the value from the Option // and panics if the value is None println!("{}", maybe_cake.unwrap()); // The expect method works much like the un...
A React component can be defined as an ES6 class that extends the base React.Component class. In its minimal form, a component must define a render method that specifies how the component renders to the DOM. The render method returns React nodes, which can be defined using JSX syntax as HTML-like ta...
What is a node.js module (link to article): A module encapsulates related code into a single unit of code. When creating a module, this can be interpreted as moving all related functions into a file. Now lets see an example. Imagine all files are in same directory: File: printer.js "use...
Switch statements compare a single test value to multiple conditions, and performs any associated actions for successful comparisons. It can result in multiple matches/actions. Given the following switch... switch($myValue) { 'First Condition' { 'First Action' } 'Second Condition' ...
The -Regex parameter allows switch statements to perform regular expression matching against conditions. Example: switch -Regex ('Condition') { 'Con\D+ion' {'One or more non-digits'} 'Conditio*$' {'Zero or more "o"'} 'C.ndition' {'Any single char.'} '^C\w+ition$'...
The break keyword can be used in switch statements to exit the statement before evaluating all conditions. Example: switch('Condition') { 'Condition' { 'First Action' } 'Condition' { 'Second Action' break } 'Condition' { 'Third Action' } } Output...
The -Wildcard parameter allows switch statements to perform wildcard matching against conditions. Example: switch -Wildcard ('Condition') { 'Condition' {'Normal match'} 'Condit*' {'Zero or more wildcard chars.'} 'C[aoc]ndit[f-l]on' {'Range and set of chars...
The -Exact parameter enforces switch statements to perform exact, case-insensitive matching against string-conditions. Example: switch -Exact ('Condition') { 'condition' {'First Action'} 'Condition' {'Second Action'} 'conditioN' {'Third Action'} '^*ondition$' {'Fourth Action...
The -CaseSensitive parameter enforces switch statements to perform exact, case-sensitive matching against conditions. Example: switch -CaseSensitive ('Condition') { 'condition' {'First Action'} 'Condition' {'Second Action'} 'conditioN' {'Third Action'} } Output: Second Act...
The -file parameter allows the switch statement to receive input from a file. Each line of the file is evaluated by the switch statement. Example file input.txt: condition test Example switch statement: switch -file input.txt { 'condition' {'First Action'} 'test' {'Second Action...
The Default keyword is used to execute an action when no other conditions match the input value. Example: switch('Condition') { 'Skip Condition' { 'First Action' } 'Skip This Condition Too' { 'Second Action' } Default { 'Default Action' } } Output: D...
Fixnum#to_s takes an optional base argument and represents the given number in that base: 2.to_s(2) # => "10" 3.to_s(2) # => "11" 3.to_s(3) # => "10" 10.to_s(16) # => "a" If no argument is provided, then it represents the number in bas...
Compile errors can be generated using the preprocessor. This is useful for a number of reasons some of which include, notifying a user if they are on an unsupported platform or an unsupported compiler. e.g. Return Error if gcc version is 3.0.0 or earlier. #if __GNUC__ < 3 #error "This cod...
The Arbitrary class is for types that can be randomly generated by QuickCheck. The minimal implementation of Arbitrary is the arbitrary method, which runs in the Gen monad to produce a random value. Here is an instance of Arbitrary for the following datatype of non-empty lists. import Test.QuickC...

Page 143 of 1336