This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Filter out traditional C comments. | |
* | |
* C++ comments are not filtered out. | |
*/ | |
#include <stdio.h> | |
enum States { | |
WAITING_FOR_OPENING_SLASH, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <benchmark/benchmark.h> | |
#include <string> | |
static void Copy(benchmark::State& state) { | |
// Code inside this loop is measured repeatedly | |
for (auto _ : state) { | |
std::string src("a very long string to defeat small string optimization"); | |
std::string dst{src}; | |
benchmark::DoNotOptimize(dst); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang++ -std=c++17 -Wall -Wextra -O2 -lbenchmark flat_set_vs_std_set.cpp | |
/* | |
Run on (4 X 2300 MHz CPU s) | |
CPU Caches: | |
L1 Data 32 KiB (x2) | |
L1 Instruction 32 KiB (x2) | |
L2 Unified 256 KiB (x2) | |
L3 Unified 4096 KiB (x1) | |
Load Average: 2.59, 5.88, 5.91 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Covariance and contra-variance in std::function | |
// See | |
// https://quuxplusone.github.io/blog/2019/01/20/covariance-and-contravariance/ | |
#include <functional> | |
struct B {}; | |
struct D : B {}; | |
// std::function is covariant on return types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tee-like utility demonstrating usage of pipes. | |
// | |
// This program was originally intended to demonstrate overlapped i/o | |
// and WaitForMultipleObjects() but this proved to be quite complex and | |
// there is no need to wait concurrently on the pipe and child process | |
// as the child first emits its output (in the pipe) *then* terminates. | |
// | |
// The following command: | |
// rooibos foo.out foo bar | |
// is equivalent to: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
May the Source be with you. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Quick-and-dirty program to compare performance of stdio vs mmap i/o. | |
*/ | |
#ifdef NDEBUG | |
#undef NDEBUG // assert used for error handling | |
#endif | |
#ifdef __linux__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://www.bfilipek.com/2019/05/heterogeneous-lookup-cpp14.html | |
#include <map> | |
#include <string> | |
std::map<std::string, int> m1; | |
int f1() { | |
// Constructs a temporary string for key. | |
auto it = m1.find("foo"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gotac prints lines from standard input or files in command-line in reverse order. | |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Show difference between initialization and assignment when calling function | |
// that returns a user-defined type. | |
struct S { | |
S(); | |
~S(); | |
S(const S&); | |
S(S&&); | |
S& operator=(const S&); | |
S& operator=(S&&); |
OlderNewer