This file contains hidden or 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 <cassert> | |
| #include <iostream> | |
| template<typename T, typename R=void> | |
| struct ExtMethod { | |
| ExtMethod& operator - () { | |
| return *this; | |
| } | |
| template<typename U> |
This file contains hidden or 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
| struct MaxUsage { int memory, disk; }; | |
| TEST_CASE( "KeyValueBuffer disk memory usage" ) | |
| { | |
| using namespace Catch::Generators; | |
| MaxUsage params[] = { | |
| { 1, 2 }, | |
| { 1, 1024 }, | |
| { 8, 1024 }, |
This file contains hidden or 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
| // Define an optional chaining pipeline operator | |
| operator infix |> { associativity left } | |
| func |> <T, U>(t: T?, f: (T) -> U? ) -> U? { | |
| if let t1 = t { return f( t1 ) } | |
| else { return nil } | |
| } | |
| // some dummy classes and functions to chain together | |
| class C { let x = 7 } | |
| class B { } |
This file contains hidden or 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? |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) ) ); |
OlderNewer