This file contains hidden or 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
#!/usr/bin/env bash | |
put() { | |
for x in "$@"; do | |
echo -en "$x\0" | |
done | |
} | |
f() { | |
res=(' a b' 'c d') |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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<typename> struct T { | |
}; | |
template<> struct T<int> { | |
static const int value = 1; | |
}; | |
template<> struct T<float> { | |
static const int value = 2; | |
}; |
This file contains hidden or 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<typename> struct T { | |
}; | |
template<typename T> int f(); | |
template<> int f<T<int>>() { | |
return 1; | |
} | |
template<> int f<int>() { |
This file contains hidden or 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<typename> struct T { | |
}; | |
template<typename T> struct S { | |
}; | |
template<typename X> struct S<T<X>> { | |
static const int value = 1; | |
}; |
This file contains hidden or 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
#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); | |
} |
This file contains hidden or 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
malets@ub:~$ cat 1.C | |
#include <cstdlib> | |
struct C { | |
int *ptr; | |
int& operator*() { | |
return *ptr; | |
} | |
}; |
This file contains hidden or 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
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 |
This file contains hidden or 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
#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; |
This file contains hidden or 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
#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; |
OlderNewer