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
/** | |
* Creates an object that is never cleaned up by using placement new into a local memory buffer | |
* Useful for singletons | |
*/ | |
template<class T> | |
struct Immortal { | |
template<class... Args> | |
Immortal(Args&&... args) { | |
::new(space) T(std::forward<Args>(args)...); | |
} |
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
// this should never be able to be instantiated | |
template<typename T> | |
struct _remove_reference_wrapper; | |
template<typename T> | |
struct _remove_reference_wrapper<std::reference_wrapper<T>> { | |
using type = T; | |
}; | |
template<typename T, typename = void> |
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
template<template<class...> class tmpl, typename T> | |
struct _is_template_for : public std::false_type {}; | |
template<template<class...> class tmpl, class... Args> | |
struct _is_template_for<tmpl, tmpl<Args...>> : public std::true_type {}; | |
template<template<class...> class tmpl, typename... Ts> | |
struct is_template_for : public std::conjunction<_is_template_for<tmpl, std::decay_t<Ts>>...> {}; | |
template<template<class...> class tmpl, typename... Ts> |
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
std::string demangle_typeid_name(const std::string & mangled_name) { | |
#ifdef V8TOOLKIT_DEMANGLE_NAMES | |
// printf("Starting name demangling\n"); | |
std::string result; | |
int status; | |
auto demangled_name_needs_to_be_freed = abi::__cxa_demangle(mangled_name.c_str(), nullptr, 0, &status); | |
result = demangled_name_needs_to_be_freed; |
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
#pragma once | |
#include <type_traits> | |
#include <memory> | |
#include <string> | |
#include <string_view> | |
#include <new> | |
#include <cstdint> |
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++ foo.cpp -std=c++14 -lbenchmark -O3 | |
// zacs-MacBook-Pro:~ xaxxon$ ./a.out | |
// Run on (4 X 3100 MHz CPU s) | |
// 2016-11-13 19:35:19 | |
// Benchmark Time CPU Iterations | |
// -------------------------------------------------------- | |
// list_iteration 19084 ns 19034 ns 34159 | |
// vec_ptr_iteration 6837 ns 6809 ns 98262 |
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
class StackTraceException : public std::exception { | |
protected: | |
static constexpr int STACK_POINTER_COUNT = 100; | |
void * stack_pointers[STACK_POINTER_COUNT]; | |
std::size_t stack_pointers_filled = 0; | |
mutable std::string stacktrace; | |
public: | |
StackTraceException(); | |
~StackTraceException(); |
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
How I build: | |
$HOME/Downloads/clang+llvm-3.8.0-x86_64-apple-darwin/bin/clang++ \ | |
-fno-rtti -O0 -g \ | |
-I/Users/xaxxon/Downloads/clang+llvm-3.8.0-x86_64-apple-darwin/include \ | |
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/ \ | |
-fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual \ | |
-Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor \ | |
-Wdelete-non-virtual-dtor -Werror=date-time -std=c++11 -O3 -DNDEBUG -fno-exceptions -fno-rtti \ | |
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \ |
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
struct _Invoker_functor | |
{ // INVOKE a function object | |
template<class _Callable, | |
class... _Types> | |
static auto _Call(_Callable&& _Obj, _Types&&... _Args) | |
-> decltype(_STD forward<_Callable>(_Obj)( | |
_STD forward<_Types>(_Args)...)) | |
{ // INVOKE a function object | |
return (_STD forward<_Callable>(_Obj)( // <=== THIS LINE | |
_STD forward<_Types>(_Args)...)); |
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
mylib.h | |
#ifndef MYLIB_H | |
#define MYLIB_H | |
std::string get_operating_system_name(); | |
#endif // MYLIB_H | |
NewerOlder