1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-15 14:48:00 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Hořeňovský
ac4958395c
Rejigger OSX images on Travis 2019-10-29 23:32:24 +01:00
Martin Hořeňovský
316a5c0572
Remove type erasure in predicate matcher
Now the type of the predicate is part of the type of the
PredicateMatcher.
2019-10-29 23:28:08 +01:00
5 changed files with 31 additions and 41 deletions

View File

@ -183,25 +183,26 @@ matrix:
# 5/ OSX Clang Builds
- os: osx
osx_image: xcode8
compiler: clang
env: COMPILER='clang++'
- os: osx
osx_image: xcode9
compiler: clang
env: COMPILER='clang++'
- os: osx
osx_image: xcode9.1
compiler: clang
env: COMPILER='clang++'
- os: osx
osx_image: xcode9.1
osx_image: xcode9.4
compiler: clang
env: COMPILER='clang++' CPP14=1
- os: osx
osx_image: xcode10.3
compiler: clang
env: COMPILER='clang++' CPP14=1
- os: osx
osx_image: xcode11.2
compiler: clang
env: COMPILER='clang++' CPP14=1
- os: osx
osx_image: xcode11.2
compiler: clang
env: COMPILER='clang++' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
# 6/ Special builds -- examples, coverage, valgrind, etc.
- os: linux
compiler: gcc
@ -229,11 +230,6 @@ matrix:
packages: ['valgrind', 'lcov', 'g++-7']
env: COMPILER='g++-7' CPP14=1 VALGRIND=1
- os: osx
osx_image: xcode9.1
compiler: clang
env: COMPILER='clang++' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
# 7/ C++17 builds
- os: linux
compiler: gcc

View File

@ -33,16 +33,6 @@ The API for Catch2's console colour will be changed to take an extra
argument, the stream to which the colour code should be applied.
### Type erasure in the `PredicateMatcher`
Currently, the `PredicateMatcher` uses `std::function` for type erasure,
so that type of the matcher is always `PredicateMatcher<T>`, regardless
of the type of the predicate. Because of the high compilation overhead
of `std::function`, and the fact that the type erasure is used only rarely,
`PredicateMatcher` will no longer be type erased in the future. Instead,
the predicate type will be made part of the PredicateMatcher's type.
---
[Home](Readme.md#top)

View File

@ -44,7 +44,8 @@
* If the second argument has text outside tags, the text will be ignored.
* Hidden test cases are no longer included just because they don't match an exclusion tag
* Previously, a `TEST_CASE("A", "[.foo]")` would be included by asking for `~[bar]`.
* `PredicateMatcher` is no longer type erased.
* This means that the type of the provided predicate is part of the `PredicateMatcher`'s type
### Fixes

View File

@ -14,7 +14,7 @@
#include <memory>
#include <vector>
#include <cassert>
#include <tuple>
#include <utility>
#include <exception>

View File

@ -9,9 +9,10 @@
#include "catch_common.h"
#include "catch_matchers.h"
#include "catch_meta.hpp"
#include <functional>
#include <string>
#include <utility>
namespace Catch {
namespace Matchers {
@ -21,14 +22,14 @@ namespace Detail {
std::string finalizeDescription(const std::string& desc);
}
template <typename T>
template <typename T, typename Predicate>
class PredicateMatcher : public MatcherBase<T> {
std::function<bool(T const&)> m_predicate;
Predicate m_predicate;
std::string m_description;
public:
PredicateMatcher(std::function<bool(T const&)> const& elem, std::string const& descr)
:m_predicate(std::move(elem)),
PredicateMatcher(Predicate&& elem, std::string const& descr)
:m_predicate(std::forward<Predicate>(elem)),
m_description(Detail::finalizeDescription(descr))
{}
@ -47,9 +48,11 @@ public:
// The user has to explicitly specify type to the function, because
// inferring std::function<bool(T const&)> is hard (but possible) and
// requires a lot of TMP.
template<typename T>
Generic::PredicateMatcher<T> Predicate(std::function<bool(T const&)> const& predicate, std::string const& description = "") {
return Generic::PredicateMatcher<T>(predicate, description);
template<typename T, typename Pred>
Generic::PredicateMatcher<T, Pred> Predicate(Pred&& predicate, std::string const& description = "") {
static_assert(is_callable<Pred(T)>::value, "Predicate not callable with argument T");
static_assert(std::is_same<bool, FunctionReturnType<Pred, T>>::value, "Predicate does not return bool");
return Generic::PredicateMatcher<T, Pred>(std::forward<Pred>(predicate), description);
}
} // namespace Matchers