Skip to content

Instantly share code, notes, and snippets.

View oliora's full-sized avatar

Andrey Upadyshev oliora

View GitHub Profile
#include <type_traits>
#include <utility>
#include <algorithm>
namespace has_own_find_impl__ {
struct two__ { char c__[2]; };
template <class T> static two__ test__(...);
template <class T> static char test__(decltype(std::declval<T>().find(std::declval<typename T::key_type>()))* = 0);
@oliora
oliora / test_uref_types.cpp
Last active February 18, 2016 09:37
Print value category and constness of a universal reference for all the different argument options
#include <iostream>
#include <type_traits>
#include <utility>
namespace {
struct Func
{
Func() = default;
// Developing of the topic, see previous gists:
// 1. https://gist.github.com/oliora/b8207b4a74a6bb868ef4
// 2. https://gist.github.com/pudov/0b1572989c418684c381
#include <type_traits>
#include <utility>
#include <vector>
#include <set>
// Let's use std::void_t. Unfortunately it's introduced in C++17 but you can easily add it by yourself
@oliora
oliora / simple_orm.h
Last active March 3, 2016 23:50
Concept of Simple ORM made with C++11
// Simple ORM = SORM
namespace sorm {
namespace details {
template<size_t N, class Statement, class P>
inline void bind_params(Statement& stmt, const P& p)
{
bind_param(stmt, N, p);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!--See more at http://superuser.com/a/1064474/581948-->
<key>Label</key>
<string>NAME.sshfs</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/sshfs</string>
@oliora
oliora / map_insert_test.cpp
Last active September 26, 2016 08:16
Test of performance bug with some std::map and std::unordered_map implementations
// Test of performance bug with some std::map and std::unordered_map implementations
// see http://www.forwardscattering.org/post/37 for details.
//
// Written by Andrey Upadyshev https://github.com/oliora/ based on article's test code
#include <unordered_map>
#include <map>
#include <iostream>
#include <iomanip>
#include <chrono>
#include <type_traits>
@oliora
oliora / perf_timer.h
Created September 26, 2016 08:14
Performance timer in pure C++11
#include <chrono>
#include <type_traits>
// Floating seconds duration
using fseconds = std::chrono::duration<double>;
class PerfTimer
{
public:
using clock = std::conditional<
@oliora
oliora / constexpr_assert.h
Last active May 24, 2022 03:01
constexpr_assert
// A compilation of the following posts:
// http://stackoverflow.com/questions/18648069/g-doesnt-compile-constexpr-function-with-assert-in-it
// http://ericniebler.com/2014/09/27/assert-and-constexpr-in-cxx11/
#include <cassert>
#include <utility>
template<class Assert>
inline void constexpr_assert_failed(Assert&& a) noexcept { std::forward<Assert>(a)(); }
// When evaluated at compile time emits a compilation error if condition is not true.
@oliora
oliora / delegating_deleter.h
Last active May 31, 2017 22:59
Delegating deleter
/////////////////////////////////////////////
// parser.h
#include <memory>
template<class T>
struct delegating_delete {
inline void operator() (T *p) const noexcept { do_delete(p); }
};
namespace parser {
@oliora
oliora / forward_ref_ctor_assignment.cpp
Created November 16, 2017 09:43
It's a bit tricky to get constructor and assignment operator accepting forward reference (singular or variadic) right
#include <type_traits>
#include <utility>
struct Bar {};
// Note about `is_convertible<T&&, Foo>`. `T&&` is essential there!
struct Foo
{
template<class T, class = typename std::enable_if<!std::is_convertible<T&&, Foo>::value>::type>
Foo(T&& t) {}