Skip to content

Instantly share code, notes, and snippets.

Avatar
🐶
eth sleep repeat

Viktor Kirilov onqtam

🐶
eth sleep repeat
View GitHub Profile
View __VA_NARG__.cpp
https://groups.google.com/forum/#!msg/comp.std.c/d-6Mj5Lko_s/5R6bMWTEbzQJ
/* The PP_NARG macro returns the number of arguments that have been
* passed to it.
*/
#define PP_NARG(...) \
PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
#define PP_NARG_(...) \
PP_ARG_N(__VA_ARGS__)
View optimize_bool.cpp
// compile with and without optimizations (GCC) - are '1' and '0' the only possibilities? :)
// https://wandbox.org/permlink/0K9SsiicMvRSyoDW
#include <cstdio>
void print(int x) { printf("x = %d!\n", x); }
int main() {
bool* b = new bool;
print(*b ? 1 : 0);
View fast_static.h
#pragma once
#ifdef __GNUC__
#pragma GCC system_header // to silence "ISO C++11 requires at least one argument for the "..." in a variadic macro"
#endif // __GNUC__
#include <utility> // std::forward
#include <memory> // placement new
#ifdef __clang__
View multi_virtual_inheritance_mindfuck.cpp
#include <iostream>
struct A {
virtual void foo() = 0;
};
struct B {
virtual void foo() = 0;
};
View this_is_null.cpp
class FirstBase {
int firstBaseData;
};
class SecondBase {
public:
void Method()
{
if( this == 0 ) {
printf( "this == 0");
View for_each_argument.cpp
#include <iostream>
template <class F, class... Args>
void for_each_argument(F f, Args&&... args) {
[](...){}((f(std::forward<Args>(args)), 0)...);
}
void print(int in) {
std::cout << in << std::endl;
}
View exit().cpp
#include <cstdlib>
#include <iostream>
using namespace std;
struct RAII {
RAII() { cout << "ctor" << endl; }
~RAII() { cout << "dtor" << endl; }
};
RAII global; // dtor WILL be called!
View overloaded_operators_for_enum.cpp
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
enum class Crap {
A = 0,
B,
C,
View bad string throw.cpp
#include <cstdio>
#include <cstring>
struct RAII {
~RAII() {
char buf[1000];
memset(buf, 'A', 1000);
}
};
void thrower() {
View exceptions.cpp
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
try {
char* p = new char[10485760000];
delete [] p;
cout << "alloced!" << endl;
} catch(std::exception& e) {
You can’t perform that action at this time.