Searching element in std::map by Value
External Sorting Criteria / Comparator
External sorting criteria i.e. Comparator
std::map with external sorting criteria i.e. Comparator
It's not all that hard to implement a finite-state machine, unless it's very large, and you have to worry about multithreading, and ...
A common design technique in the repertoire of most programmers is the venerable state machine. Designers use this programming construct to break complex problems into manageable states and state transitions. There are innumerable … Read More →
Simple Sorting Challenge
Write a program which sorts numbers.
Your program should accept as its first argument a path to a filename. Input example is the following
70.920 -38.797 14.354 99.323 90.374 7.581
-37.507 -3.263 40.079 27.999 65.213 -55.552
Print sorted numbers in the following way. Please note, that you need to print the numbers till … Read More →
FakeIt is a simple mocking framework for C++. It supports GCC, Clang and MS Visual C++ - https://github.com/eranpeer/FakeIt
FakeIt is written in C++11 and can be used for testing both C++11 and C++ projects.
Checkout the Quickstart for many more examples!
Download the Latest Release and start using FakeIt now!
Mock objects - http://clean-cpp.org/mock-objects/
Unit tests follow a simple pattern. … Read More →
This class manages socket timeouts by applying the concept of a deadline.Some asynchronous operations are given deadlines by which they must complete. Deadlines are enforced by an "actor" that persists for the lifetime of the client object.
If the deadline actor determines that the deadline has expired, the socket is closed and any outstanding operations are … Read More →
Welcome to the Getting Started with MongoDB guide. This guide provides instructions to get you started using MongoDB. The guide covers the following topics:
Introduction to MongoDB as well as instructions to Import Example Dataset;
A brief overview of the C++ MongoDB Driver;
Basic Insert, Find, Update, Remove operations plus Aggregation;
Instructions on creating Indexes to improve query performance.
The … Read More →
One of the most foundational principles of good design is:
Gather together those things that change for the same reason, and separate those things that change for different reasons.
This principle is often known as the Single Responsibility Principle or SRP. In short, it says that a subsystem, module, class, or even … Read More →
1. GCC (GNU Compiler Collection)
1.1 A Brief History and Introduction to GCC
The original GNU C Compiler (GCC) is developed by Richard Stallman, the founder of the GNU Project. Richard Stallman founded the GNU project in 1984 to create a complete Unix-like operating system as free software, to promote freedom and cooperation among computer users and programmers.
GCC, formerly … Read More →
The Poisson distribution is a well-known statistical discrete distribution. It expresses the probability of a number of events (or failures, arrivals, occurrences ...) occurring in a fixed period of time, provided these events occur with a known mean rate λ (events/time), and are independent of the time since the last event.
The distribution was discovered by Simé on-Denis … Read More →
Code source for directory tree in LINUX using C++
C++ Copy Constructor passed by value or by reference ?
The parameter in the copy constructor A(A other) is an instance of type A.
When the copy constructor is executed, it calls the copy constructor itself because of the pass-by-value parameter.
Since endless recursive calls cause call stack overflow, a pass-by-value parameter is not allowed in the C++ … Read More →
Static Shared Library in C - Linux
1. Create a C file with a function - example :
int addnumbers(int a , int b)
total = a + b;
2. The next step is to complile this file :
gcc -c … Read More →
To create the shared (*.so) library, use these steps
Example instructions for compiling
1) g++ -fpic -c CLib.cpp
2) g++ -shared -o libCLib.so CLib.o
3) g++ CLibTest.cpp -o CLibTest -L. -lCLib
C Programming Tutorial in Linux #040 - Dynamic Shared Library
Tell your C++ compiler which instantiations to make while it is compiling your template class's .cpp file.
(If you've already read the previous FAQ, this answer is completely symmetric with that one, so you can probably skip this answer.)
As an example, consider the header file Foo.h which contains the following template class. Note that method Foo<T>::f() … Read More →
Google C++ Style Guide
Table of Contents
The #define Guard
Function Parameter Ordering
Names and Order of Includes
Nonmember, Static Member, and Global Functions
Static and Global Variables
Doing Work in Constructors
Copyable and Movable Types
Delegating and Inheriting Constructors
Structs vs. Classes
Write Short Functions
Ownership and Smart Pointers
Other C++ Features
Default … Read More →
Since a time_t is only required to represent time intervals of ±68 years, and many implementations use a base year of 1970 for representing the current time, there is an inability for many popular C++ implementations to represent dates and times after 2038. This means that a lot of software could break in 2038, if … Read More →
This piece of code illustrates how your compiler library handles different settings of the TZ environment variable. It also shows
the problematics arising from time zone conversion localtime/gmtime when daylight saving is currently in effect and the time to be converted would have no daylight time set and vice versa.
In your shell set the environment variable … Read More →
This is because of structure alignment. Structure alignment refers to the ability of the compiler to insert unused memory into a structure so that data members are optimally aligned for better performance. Many processors perform best when fundamental data types are stored at byte-addresses that are multiples of their sizes.
Here's an example using typical settings … Read More →
You have two objects, and you need to know if their respective classes have a base class/derived class relationship or if they are unrelated.
Use the dynamic_cast operator to attempt to downcast from one type to another. The result tells you about the class’s relationships.
Example presents some code for doing this.
Determining class relationships
using namespace … Read More →