Skip to content

Instantly share code, notes, and snippets.

I don't find this "cache end()" guideline of LLVM right: http://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop It's a case of premature optimization, and it actually leaves room for error because the new identifier is a non-const lvalue.
@wilhelmtell
wilhelmtell / exclusive.cc
Last active August 29, 2015 14:18
Extract responsibility for exclusivity in a RAII class?
#include <utility>
#include <iostream>
struct exclusive {
exclusive() : o{true} { std::cout << this << " exclusive init\n"; }
~exclusive() {
if(owning())
std::cout << this << " exclusive cleanup\n";
else
std::cout << this << " exclusive no cleanup\n";
#include <cmath>
int main() {
auto const cos = [](auto const& exp) { return [&]() { return std::cos(exp()); }; };
auto const sin = [](auto const& exp) { return [&]() { return std::sin(exp()); }; };
auto const term = [](auto const& x) { return [&]() { return x; }; };
auto const eval = [](auto const& exp) { return exp(); };
std::cout << eval(cos(sin(term(0.5 * M_PI)))) << '\n';
}

Keybase proof

I hereby claim:

  • I am wilhelmtell on github.
  • I am wilhelmtell (https://keybase.io/wilhelmtell) on keybase.
  • I have a public key whose fingerprint is 8702 6ACC 79E5 235F 11A3 837D D428 19EA D130 1F36

To claim this, I am signing this object: