Skip to content

Commit

Permalink
Merge branch 'develop' into value-default
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Sep 10, 2016
2 parents 5efe6c4 + f184575 commit 00a8e62
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 67 deletions.
88 changes: 46 additions & 42 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
sudo: required
dist: trusty
language: cpp
script: cmake

Expand All @@ -9,58 +11,59 @@ matrix:
compiler: clang

# Clang
- env: CLANG_VERSION=3.4 ASAN=on LIBCXX=off
# - env: CLANG_VERSION=3.4 ASAN=on LIBCXX=off
# os: linux
# compiler: clang
# addons: &clang34
# apt:
# packages:
# - g++-4.9
# - clang-3.4
# - valgrind
# sources:
# - ubuntu-toolchain-r-test

# - env: CLANG_VERSION=3.4 ASAN=on LIBCXX=off CXX11=on
# os: linux
# compiler: clang
# addons: *clang34

- env: CLANG_VERSION=3.5 ASAN=on LIBCXX=on
os: linux
compiler: clang
addons: &clang34
compiler: clang-3.5
addons: &clang35
apt:
packages:
- util-linux
- g++-4.9
- clang-3.5
- valgrind
sources:
- ubuntu-toolchain-r-test

- env: CLANG_VERSION=3.4 ASAN=on LIBCXX=off CXX11=on
- env: CLANG_VERSION=3.5 ASAN=on LIBCXX=off
os: linux
compiler: clang
addons: *clang34

# - env: CLANG_VERSION=3.5 ASAN=on LIBCXX=on
# os: linux
# compiler: clang-3.5
# addons: &clang35
# apt:
# packages:
# - util-linux
# - clang-3.5
# - valgrind
# sources:
# - ubuntu-toolchain-r-test
# - llvm-toolchain-precise-3.5
compiler: clang-3.5
addons: *clang35

# - env: CLANG_VERSION=3.5 ASAN=on LIBCXX=off
# os: linux
# compiler: clang-3.5
# addons: *clang35

# - env: CLANG_VERSION=3.7 ASAN=off LIBCXX=on BUILD_EXAMPLES=on
# os: linux
# compiler: clang-3.7
# addons: &clang37
# apt:
# packages:
# - util-linux
# - clang-3.7
# - valgrind
# - python
# sources:
# - ubuntu-toolchain-r-test
# - llvm-toolchain-precise-3.7
- env: CLANG_VERSION=3.8 ASAN=off LIBCXX=on BUILD_EXAMPLES=on
os: linux
compiler: clang-3.8
addons: &clang38
apt:
packages:
- util-linux
- g++-4.9
- clang-3.8
- valgrind
- python
sources:
- ubuntu-toolchain-r-test

# - env: CLANG_VERSION=3.7 ASAN=off LIBCXX=off BUILD_EXAMPLES=on
# os: linux
# compiler: clang-3.7
# addons: *clang37
- env: CLANG_VERSION=3.8 ASAN=off LIBCXX=off BUILD_EXAMPLES=on
os: linux
compiler: clang-3.8
addons: *clang38

# Gcc
- env: GCC_VERSION=4.9 ASAN=off LIBCXX=off
Expand Down Expand Up @@ -112,7 +115,7 @@ install:
- export CHECKOUT_PATH=`pwd`;
- if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
- if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi
- if [[ "$CLANG_VERSION" == "3.4" ]]; then export CXX="/usr/local/clang-3.4/bin/clang++" CC="/usr/local/clang-3.4/bin/clang"; fi
# - if [[ "$CLANG_VERSION" == "3.4" ]]; then export CXX="/usr/local/clang-3.4/bin/clang++" CC="/usr/local/clang-3.4/bin/clang"; fi
# Setup deps directory
- export DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- mkdir ${DEPS_DIR} && cd ${DEPS_DIR}
Expand All @@ -134,6 +137,7 @@ install:
if [[ "${CLANG_VERSION}" == "3.5" ]]; then LLVM_VERSION="3.5.2"; fi
if [[ "${CLANG_VERSION}" == "3.6" ]]; then LLVM_VERSION="3.6.2"; fi
if [[ "${CLANG_VERSION}" == "3.7" ]]; then LLVM_VERSION="3.7.0"; fi
if [[ "${CLANG_VERSION}" == "3.8" ]]; then LLVM_VERSION="3.8.1"; fi
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz"
Expand Down
6 changes: 6 additions & 0 deletions example/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ FIT_STATIC_LAMBDA_FUNCTION(tuple_dot) = [](auto&& a, auto&& b)
return tuple_fold(product, [](auto x, auto y) { return x+y; });
};

void run_each()
{
auto t = std::make_tuple(1, 2);
tuple_for_each(t, [](int i) { std::cout << i << std::endl; });
}

void run_transform()
{
auto t = std::make_tuple(1, 2);
Expand Down
4 changes: 2 additions & 2 deletions include/fit/apply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ struct apply_f

#endif
template<class F, class... Ts>
constexpr FIT_SFINAE_RESULT(F, id_<Ts>...)
operator()(F&& f, Ts&&... xs) const FIT_SFINAE_RETURNS
constexpr FIT_SFINAE_MANUAL_RESULT(F, id_<Ts>...)
operator()(F&& f, Ts&&... xs) const FIT_SFINAE_MANUAL_RETURNS
(
f(FIT_FORWARD(Ts)(xs)...)
);
Expand Down
13 changes: 4 additions & 9 deletions include/fit/arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,13 @@ namespace detail {
template<class T>
struct perfect_ref
{
typedef T&& type;
typedef T type;
typedef typename std::remove_reference<T>::type value_type;
T&& value;
constexpr perfect_ref(T&& x) : value(FIT_FORWARD(T)(x))
constexpr perfect_ref(value_type& x) : value(FIT_FORWARD(T)(x))
{}
};

template<class T>
constexpr perfect_ref<T> make_perfect_ref(T&& x)
{
return { FIT_FORWARD(T)(x) };
}

template<std::size_t N>
struct ignore
{
Expand All @@ -89,7 +84,7 @@ constexpr args_at<N...> make_args_at(seq<N...>)
template<std::size_t N, class... Ts>
constexpr auto get_args(Ts&&... xs) FIT_RETURNS
(
detail::make_args_at(typename gens<N>::type())(nullptr, make_perfect_ref(FIT_FORWARD(Ts)(xs))...)
detail::make_args_at(typename gens<N>::type())(nullptr, FIT_RETURNS_CONSTRUCT(perfect_ref<Ts>)(xs)...)
);

template<class T, T N>
Expand Down
14 changes: 3 additions & 11 deletions include/fit/lazy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,8 @@ namespace detail {

struct placeholder_transformer
{
template<class T>
struct transformer
{
template<class... Ts>
constexpr auto operator()(Ts&&... xs) const FIT_RETURNS
(fit::arg_c<std::is_placeholder<T>::value>(FIT_FORWARD(Ts)(xs)...));
};

template<class T, typename std::enable_if<(std::is_placeholder<T>::value > 0), int>::type = 0>
constexpr transformer<T> operator()(const T&) const
constexpr detail::make_args_f<std::size_t, std::is_placeholder<T>::value> operator()(const T&) const
{
return {};
}
Expand Down Expand Up @@ -115,8 +107,8 @@ struct ref_transformer
struct id_transformer
{
template<class T>
constexpr auto operator()(const T& x) const
FIT_SFINAE_RETURNS(always_ref(x));
constexpr auto operator()(T&& x) const
FIT_SFINAE_RETURNS(always_detail::always_base<T>(FIT_FORWARD(T)(x)));
};

FIT_DECLARE_STATIC_VAR(pick_transformer, conditional_adaptor<placeholder_transformer, bind_transformer, ref_transformer, id_transformer>);
Expand Down
17 changes: 14 additions & 3 deletions include/fit/protect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@
/// * [ConstCallable](ConstCallable)
/// * MoveConstructible
///
/// Example
/// -------
///
/// #include <fit.hpp>
/// #include <cassert>
/// using namespace fit;
///
/// int main() {
/// auto lazy_id = lazy(identity)(_1);
/// auto lazy_apply = lazy(apply)(protect(lazy_id), _1);
/// assert(lazy_apply(3) == 3);
/// }
///

#include <utility>
#include <fit/reveal.hpp>
Expand All @@ -48,9 +61,7 @@ template<class F>
struct protect_adaptor : detail::callable_base<F>
{
typedef protect_adaptor fit_rewritable1_tag;
template<class... Ts>
constexpr protect_adaptor(Ts&&... xs) : detail::callable_base<F>(FIT_FORWARD(Ts)(xs)...)
{}
FIT_INHERIT_CONSTRUCTOR(protect_adaptor, detail::callable_base<F>)
};

FIT_DECLARE_STATIC_VAR(protect, detail::make<protect_adaptor>);
Expand Down
6 changes: 6 additions & 0 deletions test/apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ FIT_TEST_CASE()
FIT_TEST_CHECK(fit::apply(binary_class(), 1, 2) == 3);
}

FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::apply(fit::apply, binary_class(), 1, 2) == 3);
FIT_STATIC_TEST_CHECK(fit::apply(fit::apply, binary_class(), 1, 2) == 3);
}

struct member_sum_f
{
int i;
Expand Down
5 changes: 5 additions & 0 deletions test/lambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ FIT_STATIC_LAMBDA_FUNCTION(add_one) = [](int x)
return x + 1;
};

FIT_TEST_CASE()
{
FIT_TEST_CHECK(add_one(2) == 3);
}

FIT_STATIC_LAMBDA_FUNCTION(sum_partial) = fit::partial([](int x, int y)
{
return x + y;
Expand Down
15 changes: 15 additions & 0 deletions test/lazy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,18 @@ FIT_TEST_CASE()
auto b = fit::lazy(dummy_unary_fn())(bad_unary_fn());
b(0);
}


struct by_value_fn
{
template<typename T, typename U>
void operator()(T &&, U &&) const
{
static_assert(std::is_same<U, int>::value, "");
}
};

FIT_TEST_CASE()
{
fit::lazy(by_value_fn{})(std::placeholders::_1, 42)("hello");
}
26 changes: 26 additions & 0 deletions test/protect.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <fit/protect.hpp>
#include <fit/lazy.hpp>
#include <fit/placeholders.hpp>
#include <memory>
#include "test.hpp"

#include <fit/function.hpp>

int f(int x)
{
return x;
Expand Down Expand Up @@ -268,3 +271,26 @@ FIT_TEST_CASE()
FIT_TEST_CHECK(constify(fit::protect(fit::lazy(f)(std::placeholders::_1)))(0, i[1]) == 0);
FIT_TEST_CHECK(constify(fit::protect(fit::lazy(f)(std::placeholders::_2)))(0, i[1]) == 1);
}

FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::lazy(fit::apply)(fit::protect(fit::lazy(fit::identity)(fit::_1)), fit::_1)(17) == 17);
FIT_TEST_CHECK(fit::lazy(fit::apply)(fit::protect(fit::lazy(fit::identity)(fit::_1)), 17)() == 17);
FIT_STATIC_TEST_CHECK(fit::lazy(fit::apply)(fit::protect(fit::lazy(fit::identity)(fit::_1)), fit::_1)(17) == 17);
FIT_STATIC_TEST_CHECK(fit::lazy(fit::apply)(fit::protect(fit::lazy(fit::identity)(fit::_1)), 17)() == 17);
}

namespace test1 {

int id(int x)
{
return x;
}

FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::lazy(fit::apply)(fit::protect(fit::lazy(id)(std::placeholders::_1)), std::placeholders::_1)(17) == 17);
FIT_TEST_CHECK(fit::lazy(fit::apply)(fit::protect(fit::lazy(id)(std::placeholders::_1)), 17)() == 17);
}

}

0 comments on commit 00a8e62

Please sign in to comment.