This file contains 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 <stdio.h> | |
using cstr = const char * const; | |
static cstr constexpr past_last_slash(cstr str, cstr last_slash) | |
{ | |
return | |
*str == '\0' ? last_slash : | |
*str == '/' ? past_last_slash(str + 1, str + 1) | |
: past_last_slash(str + 1, last_slash); | |
} |
This file contains 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 <assert.h> | |
template <typename T> | |
class comparison_impl | |
{ | |
const T& thisT() const { return *static_cast<const T*>(this); } | |
public: | |
// operator== is implemented by T | |
template <typename U> |
This file contains 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 <assert.h> | |
// This one vanishes in library | |
template <typename T, typename DerefT> | |
class iterator_facade | |
{ | |
T& thisT() { return static_cast< T&>(*this); } | |
const T& thisT() const { return static_cast<const T&>(*this); } | |
public: |
This file contains 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 <string> | |
class Foo | |
{ | |
const std::string str; | |
public: | |
Foo(const std::string &str_) : str{str_} {} | |
~Foo() { std::cout << str << " Foo's dtor called." << std::endl; } | |
}; |
This file contains 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
odd_squares = [] | |
for x in range(0, 19): | |
if x % 2 == 1: | |
odd_squares.append(x * x) | |
print(odd_squares) | |
# same in one line: | |
print([x * x for x in range(0, 19) if x % 2 == 1]) |
This file contains 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 <string> | |
#include <vector> | |
#include <iterator> | |
#include <algorithm> | |
#include <cassert> | |
using namespace std; | |
template <typename IT> |
This file contains 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> | |
int main() { | |
auto List ([](auto ...params) { | |
return [=](auto f) { | |
return f(params...); | |
}; | |
}); | |
auto Tail ([=](auto f) { | |
return f([=](auto p, auto ...rest) { |
This file contains 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 <optional> | |
/// library part | |
template <typename R, typename ... P> | |
auto lift_optional(R (*f)(P ... ps)) | |
{ | |
return [f](std::optional<P> ... xs) -> std::optional<R> { | |
if ((xs && ...)) { |
This file contains 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 stack | |
{- stack --install-ghc runghc --package aeson --package hspec -} | |
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Applicative | |
import Data.Aeson | |
import Test.Hspec | |
-- Rocket.hs library file |
This file contains 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 stack | |
-- stack --resolver lts-10.7 --install-ghc runghc | |
import Control.Concurrent (threadDelay) | |
import Control.Monad.State | |
data TrafficLightColor = Red | Yellow | Green deriving Show | |
type TrafficLightState = (TrafficLightColor, Int) |
OlderNewer