This file contains hidden or 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 <cstdint> | |
#include <iostream> | |
#include <iterator> | |
#include <type_traits> | |
using namespace std; | |
// ----------------------------------------------------------------------------- | |
// Traits for treating enums like flags, and/or giving the ability to loop over | |
// them |
This file contains hidden or 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 <cstddef> | |
#include <iostream> | |
#include <string> | |
#include <tuple> | |
#include <type_traits> | |
#include <utility> | |
using namespace std; | |
template <typename T> |
This file contains hidden or 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 <iostream> | |
#include <string> | |
#include <type_traits> | |
using namespace std; | |
struct Foo | |
{ | |
Foo() {} | |
Foo(const Foo&) |
This file contains hidden or 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 <cstddef> | |
#include <iostream> | |
#include <string> | |
#include <utility> | |
using namespace std; | |
template <bool div3, bool div5> | |
struct printer | |
{ |
This file contains hidden or 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 <iostream> | |
using namespace std; | |
constexpr unsigned long long fnv_hash64_r(unsigned long long result, const char* string) | |
{ | |
return (*string == 0) ? result : fnv_hash64_r(1099511628211ULL * result ^ *string, string + 1); | |
} | |
constexpr unsigned long long fnv_hash64(const char* string) | |
{ |
This file contains hidden or 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 <iostream> | |
#include <tuple> | |
using namespace std; | |
// When tuples get large, compile times suffer because the compiler is hashing | |
// the name of a really long type. Lambdas offer a way to truncate that type | |
// name, leading to faster compile times and the ability to instantiate larger | |
// tuples (the template depth quickly exceeds the max). | |
// Compare compile times: |
This file contains hidden or 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 <iostream> | |
#include <type_traits> | |
#include <utility> | |
template<class F> | |
struct wrapper | |
{ | |
static_assert(std::is_empty<F>(), "Lambdas must be empty"); | |
template<class... Ts> | |
decltype(auto) operator()(Ts&&... xs) const |
This file contains hidden or 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 <algorithm> | |
#include <cassert> | |
#include <utility> | |
#include <iostream> | |
using namespace std; | |
class Light | |
{ | |
public: | |
void turn_on() { m_on = true; }; |
This file contains hidden or 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
//------------------------------------------------------------------------------ | |
// A function that will apply a function to each argument | |
#include <initializer_list> | |
#include <utility> | |
template <typename F, typename... Ts> | |
void for_each_arg(F&& f, Ts&&... ts) | |
{ | |
using I = std::initializer_list<int>; | |
(void) I { (std::forward<F>(f)(std::forward<Ts>(ts)), 0)... }; |