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
trait Square { | |
fn size(&self) -> f64; | |
fn perimeter(&self) -> f64; | |
} | |
trait Circle { | |
fn radius(&self) -> f64; | |
fn perimeter(&self) -> f64; | |
} |
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
TEST_CASE("initialize rewind", "[rewind]") { | |
int rc; | |
MDB_env *env; | |
MDB_dbi dbi; | |
MDB_txn *txn; | |
SECTION("create and open an environment") { | |
REQUIRE(SuccessFrom(mdb_env_create(&env))); | |
REQUIRE(SuccessFrom(mdb_env_set_mapsize(env, size_t(1048576000)))); |
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
SCENARIO("initialize rewind", "[rewind]") { | |
GIVEN( "an uninitialised environment") { | |
int rc; | |
MDB_env *env; | |
MDB_dbi dbi; | |
MDB_txn *txn; | |
WHEN("an environment is created and opened") { | |
REQUIRE(SuccessFrom(mdb_env_create(&env))); | |
REQUIRE(SuccessFrom(mdb_env_set_mapsize(env, size_t(1048576000)))); |
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
TEST_CASE("initialize rewind", "[rewind]") { | |
int rc; | |
MDB_env* env; | |
MDB_dbi dbi; | |
MDB_txn *txn; | |
REQUIRE( SuccessFrom( mdb_env_create(&env) ) ); | |
REQUIRE( SuccessFrom( mdb_env_set_mapsize(env, size_t(1048576000) ) ) ); | |
REQUIRE( SuccessFrom( mdb_env_set_maxdbs(env, 1024) ) ); | |
REQUIRE( SuccessFrom( mdb_env_open(env, "/tmp", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664) ) ); |
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
class SuccessFrom { | |
const int rc; | |
public: | |
SuccessFrom( int rc ) : rc(rc) {} | |
explicit operator bool() const { | |
return rc == SUCCESS; | |
} | |
friend std::ostream& operator<<( std::ostream& os, SuccessFrom const& result ) { | |
return os << mdb_strerror(result.rc); |
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 "clara.hpp" | |
#include <iostream> | |
int main( int argc, char** argv ) { | |
int count = 0; | |
using namespace clara; | |
auto cli = Parser() | Opt( [&]( bool ) { count++; } ) | |
["-s"]; | |
cli.parse( Args{ argc, argv } ); | |
std::cout << "Repeated: " << count << ", effective " << std::boolalpha << (count%2==1) << " (Command line was:"; |
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 <experimental/optional> | |
#include <string> | |
#include <iostream> | |
using std::experimental::optional; | |
template<typename T> | |
struct add_optionality { using type = optional<T>; }; | |
template<typename T> |
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
extension Sequence { | |
func countIf( predicate: (Self.Iterator.Element) -> Bool ) -> Int { | |
return reduce( 0 ) { predicate($1) ? $0+1 : $0 } | |
} | |
} |
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
var a : Int? = 11 | |
var b : Int? = 20 | |
if let a = a, | |
let b = b, | |
let c = { () -> Int? in | |
return a > 10 ? a+b : nil | |
} () { | |
println( "c: \(c)" ) | |
} |
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
var key : String? | |
let res = getPathComponents( file ) | |
>>= { (let components ) -> Result<FileTypes> in | |
key = components.filenameWithoutExt | |
return FileTypes.fromExt( components.ext ) | |
} | |
>>= { (let type ) -> Result<Void> in | |
switch type { | |
case .Video, .Image: | |
var caption : String? |
NewerOlder