Skip to content

Instantly share code, notes, and snippets.

View andrey-malets's full-sized avatar

Andrey Malets andrey-malets

  • Yandex, Ural State University
  • Yekaterinburg
View GitHub Profile
#!/usr/bin/env bash
put() {
for x in "$@"; do
echo -en "$x\0"
done
}
f() {
res=(' a b' 'c d')
#!/usr/bin/env bash
set -e -o pipefail
dev=${1:?usage: $0 <device name>}
dir="/sys/block/$dev"
if ! [[ -d "$dir" ]]; then
echo "$dev probably is not a block device (no $dir)" >&2
exit 1
template<typename> struct T {
};
template<> struct T<int> {
static const int value = 1;
};
template<> struct T<float> {
static const int value = 2;
};
template<typename> struct T {
};
template<typename T> int f();
template<> int f<T<int>>() {
return 1;
}
template<> int f<int>() {
template<typename> struct T {
};
template<typename T> struct S {
};
template<typename X> struct S<T<X>> {
static const int value = 1;
};
#include <iostream>
#include <sstream>
#include <type_traits>
template<bool is_function, typename T> struct Parser;
template<typename T> struct Parser<true, T> {
static void Parse(const std::string& input, T& parser) {
parser(input);
}
@andrey-malets
andrey-malets / 1.C
Last active December 20, 2015 20:10
malets@ub:~$ cat 1.C
#include <cstdlib>
struct C {
int *ptr;
int& operator*() {
return *ptr;
}
};
malets@mac:~$ cat 2.cc
constexpr int f() {
int x[] = {0};
return x[1];
}
int main(void) {
return f();
}
malets@mac:~$ clang++ -std=c++14 2.cc
#include <iostream>
#include <iterator>
#include <list>
template<typename It>
size_t DistanceImpl(It begin, It end, std::forward_iterator_tag) {
size_t result = 0;
while (begin++ != end)
++result;
return result;
#include <iostream>
#include <vector>
template<class It> using Value = typename std::iterator_traits<It>::value_type;
template<class It> Value<It> sum(It begin, It end) {
Value<It> res = 0;
while (begin != end)
res += *begin++;
return res;