Skip to content

Instantly share code, notes, and snippets.

View insooth's full-sized avatar
🏠
Working from home

Krzysztof Ostrowski insooth

🏠
Working from home
View GitHub Profile
// Having type T checks whether it is an instance of template U<V>.
// http://coliru.stacked-crooked.com/a/b5bcde32c99c7cab
#include <vector>
#include <type_traits>
template<class T, template<typename...> class U, class V = void>
struct is_instance_of : std::false_type
{};
@insooth
insooth / access-inaccesible.cpp
Last active September 6, 2017 12:33
Access inaccessible members and member functions through explicit template instantiation that escapes type system
#include <iostream>
// based on https://github.com/hliberacki/cpp-member-accessor
// LIVE: http://coliru.stacked-crooked.com/a/cc61098b18ab2c20
// works only for member-function-pointers and member-pointers
template <class T>
@insooth
insooth / recovering-type.cpp
Last active September 6, 2017 14:12
Recovering associated type through tag dispatch
// Based on: http://alexpolt.github.io/type-loophole.html
// LIVE: http://coliru.stacked-crooked.com/a/fda3b5b343980e02
#include <iostream>
#include <type_traits>
#include <utility>
template<class T, class Tag> T foo(Tag);
@insooth
insooth / decltype-var-expression.cpp
Created September 7, 2017 14:35
Type of a variable and type of an expression
// based on https://medium.com/@barryrevzin/value-categories-in-c-17-f56ae54bccbe
// LIVE: http://coliru.stacked-crooked.com/a/f5d7a811c5b9c1f6
#include <iostream>
#include <utility>
#include <type_traits>
@insooth
insooth / expression-type.cpp
Created September 7, 2017 15:22
Type of an expression
#include <iostream>
#include <utility>
// based on: https://medium.com/@barryrevzin/value-categories-in-c-17-f56ae54bccbe
// LIVE: http://coliru.stacked-crooked.com/a/38321a888132b051
template <class T>
@insooth
insooth / maybe-monad.cpp
Created January 30, 2018 12:17
Maybe Monad and Currying
#include <iostream>
#include <algorithm>
#include <iterator>
#include <thread>
#include <iomanip> // dec
#include <cassert>
@insooth
insooth / bitset.cpp
Created September 25, 2018 08:01 — forked from btaczala/bitset.cpp
#include <atomic>
#include <bitset>
#include <iostream>
#include <tuple>
#include <type_traits>
namespace details {
template <typename... Args>
unsigned long long getULL(Args... as) {
using unused = int[];
Questions to the integrator asked by Krzysztof Ostrowski:
Which repositories we use?
What is the purpose of each repository?
What is the file/directory structure defined per repository to be kept?
What is the file/directory structure of a service?
What is the purpose of the files/directories in the service directory?
Which build tools do we use?
What targets do we build?
// see LICENSE on insooth.github.io
#include <cstddef> // size_t
#include <tuple> // tuple, tuple_element
#include <type_traits> // disjunction
#include <utility> // {make_,}index_sequence
#include <iostream>