Tutorial by Examples

An std::map takes (key, value) pairs as input. Consider the following example of std::map initialization: std::map < std::string, int > ranking { std::make_pair("stackoverflow", 2), std::make_pair("docs-beta", 1) }; In an std::...
std::map and std::multimap both can be initialized by providing key-value pairs separated by comma. Key-value pairs could be provided by either {key, value} or can be explicitly created by std::make_pair(key, value). As std::map does not allow duplicate keys and comma operator performs right to left...
Removing all elements: std::multimap< int , int > mmp{ {1, 2}, {3, 4}, {6, 5}, {8, 9}, {3, 4}, {6, 7} }; mmp.clear(); //empty multimap Removing element from somewhere with the help of iterator: std::multimap< int , int > mmp{ {1, 2}, {3, 4}, {6, 5}, {8, 9}, {3, 4}, {6, 7} }; ...
An element can be inserted into a std::map only if its key is not already present in the map. Given for example: std::map< std::string, size_t > fruits_count; A key-value pair is inserted into a std::map through the insert() member function. It requires a pair as an argument: fruits_c...
std::map or std::multimap could be traversed by the following ways: std::multimap< int , int > mmp{ {1, 2}, {3, 4}, {6, 5}, {8, 9}, {3, 4}, {6, 7} }; //Range based loop - since C++11 for(const auto &x: mmp) std::cout<< x.first <<":...
There are several ways to search a key in std::map or in std::multimap. To get the iterator of the first occurrence of a key, the find() function can be used. It returns end() if the key does not exist. std::multimap< int , int > mmp{ {1, 2}, {3, 4}, {6, 5}, {8, 9}, {3, 4}, {6, 7} }; ...
The container std::map has a member function empty(), which returns true or false, depending on whether the map is empty or not. The member function size() returns the number of element stored in a std::map container: std::map<std::string , int> rank {{"facebook.com", 1} ,{"goo...
You can create multiline code snippets by indenting each line with at least four spaces or one tab: #include <stdio.h> int main() { printf("Hello World!\n"); return 0; }
Some parsers allow code to be designated by adding three backticks before and after a section of code. ``` <p><em>This</em> is an HTML example!</p> ``` Optionally, many parsers allow adding syntax highlighting by specifying the code's language immediately after the firs...
SELECT DisplayName, JoinDate, Reputation FROM Users ORDER BY JoinDate, Reputation DisplayNameJoinDateReputationCommunity2008-09-151Jeff Atwood2008-09-1625784Joel Spolsky2008-09-1637628Jarrod Dixon2008-10-0311739Geoff Dalgas2008-10-0312567
INSERT INTO Customers (FName, LName, PhoneNumber) SELECT FName, LName, PhoneNumber FROM Employees This example will insert all Employees into the Customers table. Since the two tables have different fields and you don't want to move all the fields over, you need to set which fields to insert int...
Single-line comments in Lua start with -- and continue until the end of line: -- this is single line comment -- need another line -- huh? Block comments start with --[[ and end with ]]: --[[ This is block comment. So, it can go on... and on... and on.... ]] Block comme...
The "default" for constructors is that they do not have any arguments. In case you do not specify any constructor, the compiler will generate a default constructor for you. This means the following two snippets are semantically equivalent: public class TestClass { private String tes...
Constructors can be created with any kinds of arguments. public class TestClass { private String testData; public TestClass(String testData) { this.testData = testData; } } Called like this: TestClass testClass = new TestClass("Test Data"); A class can ...
Each individual CSS Selector has its own specificity value. Every selector in a sequence increases the sequence's overall specificity. Selectors fall into one of three different specificity groups: A, B and c. When multiple selector sequences select a given element, the browser uses the styles appli...
Node.js package configurations are contained in a file called package.json that you can find at the root of each project. You can setup a brand new configuration file by calling: npm init That will try to read the current working directory for Git repository information (if it exists) and enviro...
The Lua standard library provides a pairs function which iterates over the keys and values of a table. When iterating with pairs there is no specified order for traversal, even if the keys of the table are numeric. for key, value in pairs(input_table) do print(key, " -- ", value) en...
HTML input validation is done automatically by the browser based on special attributes on the input element. It could partially or completely replace JavaScript input validation. This kind of validation can be circumvented by the user via specially crafted HTTP requests, so it does not replace serve...
Usually, Lua is being shipped with two binaries: lua - standalone interpreter and interactive shell luac - bytecode compiler Lets say we have an example program (bottles_of_mate.lua) like this: local string = require "string" function bottle_take(bottles_available) lo...
Reflection is often used as part of software testing, such as for the runtime creation/instantiation of mock objects. It's also great for inspecting the state of an object at any given point in time. Here's an example of using Reflection in a unit test to verify a protected class member contains the...

Page 83 of 1336