Skip to content

Commit

Permalink
Merge branch 'infix' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Feb 5, 2017
2 parents 919b361 + 6b2ff15 commit df45b2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
20 changes: 19 additions & 1 deletion include/fit/infix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/// Semantics
/// ---------
///
/// assert((x <infix(f)> y) == f(x, y));
/// assert(x <infix(f)> y == f(x, y));
///
/// Requirements
/// ------------
Expand All @@ -37,6 +37,24 @@
/// * [BinaryCallable](BinaryCallable)
/// * MoveConstructible
///
/// Operator precedence
/// -------------------
///
/// Infix operators have the precedence of relational operators. This means
/// operators such as `+` or `*` have higher precedence:
///
/// assert((x + y <infix(f)> z) == ((x + y) <infix(f)> z));
/// assert((x * y <infix(f)> z) == ((x * y) <infix(f)> z));
///
/// However, operators such as `|` or `==` have lower precedence::
///
/// assert((x | y <infix(f)> z) == (x | (y <infix(f)> z)));
/// assert((x == y <infix(f)> z) == (x == (y <infix(f)> z)));
///
/// Also, infix operators have left-to-right associativity:
///
/// assert(x <infix(f)> y <infix(g)> z == ((x <infix(f)> y) <infix(g)> z));
///
/// Example
/// -------
///
Expand Down
24 changes: 24 additions & 0 deletions test/infix.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <fit/infix.hpp>
#include <fit/function.hpp>
#include <fit/lambda.hpp>
#include <fit/pipable.hpp>
#include <fit/placeholders.hpp>
#include "test.hpp"

Expand Down Expand Up @@ -83,3 +84,26 @@ FIT_TEST_CASE()
FIT_TEST_CHECK(3 == (sum5(1, 2)));
FIT_STATIC_TEST_CHECK(3 == (sum5(1, 2)));
}

FIT_TEST_CASE()
{
#if (defined(__GNUC__) && !defined (__clang__))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wparentheses"
#endif
FIT_TEST_CHECK(6 == (1 + 2 <sum> 3));
FIT_TEST_CHECK(3 == 1 <sum> 2);
#if (defined(__GNUC__) && !defined (__clang__))
#pragma GCC diagnostic pop
#endif
}

struct foo {};

FIT_TEST_CASE()
{
auto f = fit::infix([](int, int) { return foo{}; });
auto g = fit::infix([](foo, foo) { return std::string("hello"); });
FIT_TEST_CHECK((1 <f> 2 <g> foo{}) == "hello");

}

0 comments on commit df45b2a

Please sign in to comment.