Skip to content

Instantly share code, notes, and snippets.

template<class T, T v>
struct integral_constant {
static constexpr T value = v;
using value_type = T;
using type = integral_constant; // using injected-class-name
constexpr operator value_type() const noexcept { return value; }
constexpr value_type operator()() const noexcept { return value; } //since c++14
};
using false_type = integral_constant<bool, false>;
using true_type = integral_constant<bool, true>;
@rolandschulz
rolandschulz / is_constexpr_memfn.cc
Last active January 28, 2019 07:02
Checking whether member function is constexpr
//Checking whether member function is constexpr
#include <array>
#include <vector>
template<typename T, typename = void>
struct has_constexpr_size : std::false_type {};
template<typename T, typename Fn, typename ...Args>
constexpr auto invoke_memfn(Fn fn, Args...args) { return (T().*fn)(args...); }
#include <unordered_map>
#include <vector>
#include <iostream>
#include <type_traits>
#include <memory>
//iteator pair - very crude range
template <typename I1, typename I2=I1>
struct iter_pair : std::pair<I1, I2>
{
//-checks=*,-modernize-use-auto,-hicpp-use-auto -extra-arg="-Weverything -Wno-missing-prototype -Wno-c++98-compat"
void f(double d, int a, int b) {
double r1 = a/b; //warning: result of integer division used in a floating point context; possible loss of precision [bugprone-integer-division]
double r2 = int{a/b};
double r3 = (int)(a/b); //redundant cast to the same type [google-readability-casting]
double r4 = int(a/b);
double r5 = static_cast<int>(a/b);
int i1 = d;
int i2 = int{d}; //error: type 'double' cannot be narrowed to 'int' in initializer list [clang-diagnostic-c++11-narrowing]
@rolandschulz
rolandschulz / dispatch_example.cc
Created January 17, 2018 22:55
Proof of concept of multi-versioned SIMD type and dispatch function
#include <immintrin.h>
#ifdef __ICC //ICC>=16
#define USE_TARGET_ATTR 0
#else //Clang (>=3.8) or GCC
#define USE_TARGET_ATTR 1
#endif
#if USE_TARGET_ATTR
#define TARGET_AVX __attribute__ ((target ("avx")))
Update (s) Perf (ns/day)
flexible non-simd 0.494 2.196
flexible 0.253 2.236
non-freeze,acc, bNemd, NH 0.186 2.253
non-ctc 0.183 2.27
non-vsite/shell 0.115 2.278
diag M 0.11 2.258
intrinsic 0.077 2.268
intrinsic, collapse 0.048 2.262
### Keybase proof
I hereby claim:
* I am rolandschulz on github.
* I am rschulz (https://keybase.io/rschulz) on keybase.
* I have a public key whose fingerprint is E0A8 00C1 496A 767D AA3F DDEE 8B21 18C9 DBF4 28AB
To claim this, I am signing this object:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="1">
<profile kind="CodeFormatterProfile" name="Gromacs" version="1">
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.lineSplit" value="80"/>
<setting id="org.eclipse.cdt.core.formatter.alignment_for_member_access" value="0"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
import sys,os,re
CMAKE_SOURCE_DIR="/home/rschulz/download/gromacs5.0"
sp=[CMAKE_SOURCE_DIR+"/src/", CMAKE_SOURCE_DIR+"/src/gromacs/legacyheaders/", os.path.abspath(os.path.dirname(sys.argv[1]))+"/"]
ll=file(sys.argv[1]).readlines()
of=file(sys.argv[1],"w")
inclp = re.compile('^# *include *"')
for l in ll: