Skip to content
This repository has been archived by the owner on Jan 2, 2022. It is now read-only.

Commit

Permalink
Tidy up.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtomschroeder committed Aug 17, 2016
1 parent 7c0559b commit ad1974a
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 36 deletions.
19 changes: 11 additions & 8 deletions demo/euler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 103,20 @@ PROBLEM(E6) {
let prime = [](auto x) {
if (x == 2) {
return true;
} else if (x < 2 || even(x)) {
}

if (x < 2 || even(x)) {
return false;
} else {
using I = std::remove_reference_t<std::remove_const_t<decltype(x)>>;
for (I i = 3, end = sqrt(x); i <= end; i = 2) {
if (multipleOf(i, x)) {
return false;
}
}

using I = std::remove_reference_t<std::remove_const_t<decltype(x)>>;
for (I i = 3, end = sqrt(x); i <= end; i = 2) {
if (multipleOf(i, x)) {
return false;
}
return true;
}
return true;

};

// What is the 10,001st prime number?
Expand Down
2 changes: 1 addition & 1 deletion demo/problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,7 @@

struct Problem {
static std::vector<std::function<void()>> problems;
Problem(std::function<void()> p) { problems.push_back(p); }
explicit Problem(std::function<void()> p) { problems.push_back(p); }
};

std::vector<std::function<void()>> Problem::problems;
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/apply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@ namespace lambda {

namespace detail {
template <class F, class Tuple, std::size_t... I>
constexpr auto apply(F &&f, Tuple &&t, std::index_sequence<I...>) {
constexpr auto apply(F &&f, Tuple &&t, std::index_sequence<I...> /*unused*/) {
return invoke(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))...);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/lambda/curry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 3,8 @@

#include "type_traits.hpp"

#include <tuple>
#include <functional>
#include <tuple>

namespace lambda {

Expand All @@ -25,12 25,12 @@ struct Curried {
}

template <std::size_t... Ns, typename... Ts>
auto call(std::index_sequence<Ns...>, Ts &&... ts) const {
auto call(std::index_sequence<Ns...> /*unused*/, Ts &&... ts) const {
return dispatch(std::get<Ns>(args)..., std::forward<Ts>(ts)...);
}

public:
Curried(F f, BoundArgs &&... args) : f(f), args(std::forward<BoundArgs>(args)...) {}
explicit Curried(F f, BoundArgs &&... args) : f(std::move(f)), args(std::forward<BoundArgs>(args)...) {}

template <typename... Ts>
auto operator()(Ts &&... ts) const {
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/dollar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 10,8 @@ constexpr std::vector<std::common_type_t<Ts...>> vector(Ts &&... ts) {
}

template <class... Ts>
constexpr auto array(Ts &&... ts) {
return std::array<std::common_type_t<Ts...>, sizeof...(ts)>{std::forward<Ts>(ts)...};
constexpr auto array(Ts &&... ts) -> std::array<std::common_type_t<Ts...>, sizeof...(ts)> {
return {std::forward<Ts>(ts)...};
}

} /* factory */
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/function_traits.hpp
Original file line number Diff line number Diff line change
@@ -1,8 1,8 @@

#pragma once

#include <type_traits>
#include <array>
#include <type_traits>

namespace lambda {

Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@ class Printer {
return p;
}

Printer() {}
Printer() = default;

Printer &operator<<(std::string s) {
std::cout << s;
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/stream/drop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 16,7 @@ class DropStream : public Stream {
public:
using Type = typename S::Type;

DropStream(S stream, I num) : stream(stream), num(num), flag(new std::once_flag) {}
DropStream(S stream, I num) : stream(std::move(stream)), num(num), flag(new std::once_flag) {}

Maybe<Type> next() {
std::call_once(*flag, [&]() {
Expand All @@ -36,7 36,7 @@ class Drop : public Pipeable {
const I num;

public:
Drop(I num) : num(num) {}
explicit Drop(I num) : num(num) {}

template <class S>
auto pipe(S stream) const {
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/stream/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@ class FilterStream : public Stream {
public:
using Type = typename S::Type;

FilterStream(S stream, F fn) : stream(stream), fn(fn) {}
FilterStream(S stream, F fn) : stream(std::move(stream)), fn(std::move(fn)) {}

Maybe<Type> next() {
while (auto s = std::move(stream.next())) {
Expand All @@ -31,7 31,7 @@ class Filter : public Pipeable {
F f;

public:
Filter(F f) : f(f) {}
explicit Filter(F f) : f(std::move(f)) {}

template <class S>
auto pipe(S stream) const {
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/stream/fold.hpp
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@

#pragma once

#include "stream.hpp"
#include "lambda.hpp"

namespace lambda {
namespace streams {
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/stream/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 13,7 @@ class Generator : public Stream {
public:
using Type = std::result_of_t<decltype(std::declval<G>)>;

Generator(G gen) : gen(gen) {}
explicit Generator(G gen) : gen(std::move(gen)) {}

Maybe<Type> next() { return some(gen()); }
};
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/stream/ints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 37,7 @@ class IntsStream : public Stream {
public:
using Type = I;

IntsStream(I begin) : begin(begin) {}
explicit IntsStream(I begin) : begin(begin) {}

Maybe<Type> next() { return some(begin ); }
};
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/stream/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@ class MapStream : public Stream {
public:
using Type = typename S::Type;

MapStream(S stream, F fn) : stream(stream), fn(fn) {}
MapStream(S stream, F fn) : stream(std::move(stream)), fn(fn) {}

Maybe<Type> next() { return std::move(stream.next()) >> fn; }
};
Expand All @@ -24,7 24,7 @@ class Map : public Pipeable {
F f;

public:
Map(F f) : f(f) {}
explicit Map(F f) : f(f) {}

template <class S>
auto pipe(S stream) const {
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/stream/mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 16,7 @@
#include "fold.hpp"

//
// TODO:
// TODO(jtomschroeder):
// - max: (fold?)
// - drop (change to 'skip')
// - list comprehension
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/stream/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@ class CollectionStream : public Stream {
public:
using Type = typename C::value_type;

CollectionStream(C &&collection)
explicit CollectionStream(C &&collection)
: collection(collection), begin(collection.cbegin()), end(collection.cend()) {}

Maybe<Type> next() { return begin != end ? some(std::move(*begin )) : none; }
Expand All @@ -40,7 40,7 @@ class FunctionStream : public Stream {
public:
using Type = typename std::result_of_t<decltype(std::declval<F>)>::value_type; // Maybe::Type

FunctionStream(F &&f) : f(f) {}
explicit FunctionStream(F &&f) : f(f) {}

Maybe<Type> next() { return f(); }
};
Expand Down
10 changes: 5 additions & 5 deletions lib/lambda/stream/take.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,7 @@ class Take : public Pipeable {
const I num;

public:
Take(I num) : num(num) {}
explicit Take(I num) : num(num) {}

template <class S>
auto pipe(S stream) const {
Expand All @@ -48,14 48,14 @@ class TakeWhileStream : public Stream {
public:
using Type = typename S::Type;

TakeWhileStream(S stream, P pred) : stream(stream), pred(pred) {}
TakeWhileStream(S stream, P pred) : stream(std::move(stream)), pred(std::move(pred)) {}

Maybe<Type> next() {
if (auto s = stream.next()) {
return pred(*s) ? s : none;
} else {
}
return none;
}

}
};

Expand All @@ -64,7 64,7 @@ class TakeWhile : public Pipeable {
P pred;

public:
TakeWhile(P pred) : pred(pred) {}
explicit TakeWhile(P pred) : pred(std::move(pred)) {}

template <class S>
auto pipe(S stream) const {
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/type_traits.hpp
Original file line number Diff line number Diff line change
@@ -1,8 1,8 @@

#pragma once

#include <type_traits>
#include "function_traits.hpp"
#include <type_traits>

namespace lambda {

Expand All @@ -16,7 16,7 @@ struct has_iterator {
template <typename U>
static long test(U *x);

static const bool value = sizeof(test<T>(0)) == 1;
static const bool value = sizeof(test<T>(nullptr)) == 1;
};

template <typename T>
Expand Down

0 comments on commit ad1974a

Please sign in to comment.