Skip to content

Instantly share code, notes, and snippets.

@buffyanamin
buffyanamin / asan_symbolize.py
Last active June 10, 2022 02:27
asan_symbolize with dsym producer
# https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/asan/scripts/asan_symbolize.py
def dsym_producer(binary_path):
base='/path/to/dSYM/dir/'
filename = os.path.basename(binary_path)
if (binary_path.endswith('.dylib')):
sym = base + filename + '.dSYM'
else:
sym = base + filename + ".app.dSYM"
print(binary_path + ' -> ' + sym)
return [sym]
namespace detail {
template <typename Res, typename... Args>
Obj<Res, Args...> NewObj(std::function<Res(Args...)>&& func) {
return std::make_shared<Obj<Res(Args...)>>(std::forward<std::function<Res(Args...)>&&>(func));
}
}
namespace detail {
template <typename F>
struct function_traits : public function_traits<decltype(&std::decay<F>::type::operator())> {};
@buffyanamin
buffyanamin / type_after_variadic.cpp
Created February 23, 2022 06:16
c++ template specify type after variadic types
// from https://www.cppstories.com/2020/09/variadic-pack-first.html/
namespace detail
{
template<typename Output, typename... Inputs>
void tempFunc(Output& output, Inputs const&... inputs)
{
// implementation of f
}
template<typename... InputsThenOutput, size_t... InputIndexes>
@buffyanamin
buffyanamin / get_nth_variadic_elem_no_tuple.cpp
Last active February 18, 2022 10:03
c++ template get nth element type from variadic arguments
template <std::size_t N, typename T, typename... types>
struct GetNthArgType {
using type = typename GetNthArgType<N - 1, types...>::type;
};
template <typename T, typename... types>
struct GetNthArgType<0, T, types...> {
using type = T;
};
@buffyanamin
buffyanamin / get_nth_variadic_elem.cpp
Created January 5, 2022 09:02
Get nth element from c++ variadic template argument
template <int I, class... Ts>
decltype(auto) get(Ts&&... ts) {
return std::get<I>(std::forward_as_tuple(ts...));
}
@buffyanamin
buffyanamin / chrono_helper.cpp
Last active December 29, 2021 08:49
chrono helper(boost & std chrono inter-convertion)
#include <boost/chrono.hpp>
#include <chrono>
// from https://github.com/boostorg/chrono/issues/41#issuecomment-538932927
namespace sc = ::std::chrono;
namespace bc = ::boost::chrono;
namespace chrono_helper {
// std::is_same_v<to_std_ratio_t<boost::ratio<N,D>>, std::ratio<N,D>>
// if and only if N, D are coprime and D is positive