Skip to content

Commit

Permalink
Add D to B cast. (#66)
Browse files Browse the repository at this point in the history
* Add D to B cast.

* parallel 4.

Co-authored-by: Bowen Fu <missing>
  • Loading branch information
BowenFu committed Jul 12, 2021
1 parent 8e82b24 commit cb68c92
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ jobs:
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --output-on-failure -C ${{env.BUILD_TYPE}}
run: ctest --output-on-failure --parallel 4 -C ${{env.BUILD_TYPE}}

2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --output-on-failure -C ${{env.BUILD_TYPE}}
run: ctest --output-on-failure --parallel 4 -C ${{env.BUILD_TYPE}}

- name: Compute Coverage
working-directory: ${{github.workspace}}/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ jobs:
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --output-on-failure -C ${{ matrix.build_type }}
run: ctest --output-on-failure --parallel 4 -C ${{ matrix.build_type }}

2 changes: 1 addition & 1 deletion .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ jobs:
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: |
ctest --output-on-failure -C ${{env.BUILD_TYPE}} --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=100" -T memcheck
ctest --output-on-failure --parallel 4 -C ${{env.BUILD_TYPE}} --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=100" -T memcheck
# --overwrite MemoryCheckSuppressionFile=/path/to/valgrind.suppressions \
7 changes: 7 additions & 0 deletions develop/matchit/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ namespace matchit
return std::any_cast<T>(std::addressof(a));
}

template <typename D, typename std::enable_if<!viaGetIfV<T, D> && std::is_base_of_v<T, D>>::type * = nullptr>
constexpr auto operator()(D const &d) const
-> decltype(static_cast<T const *>(std::addressof(d)))
{
return static_cast<T const *>(std::addressof(d));
}

template <typename B, typename std::enable_if<!viaGetIfV<T, B> && std::is_base_of_v<B, T>>::type * = nullptr>
constexpr auto operator()(B const &b) const
-> decltype(dynamic_cast<T const *>(std::addressof(b)))
Expand Down
7 changes: 7 additions & 0 deletions include/matchit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,13 @@ namespace matchit
return std::any_cast<T>(std::addressof(a));
}

template <typename D, typename std::enable_if<!viaGetIfV<T, D> && std::is_base_of_v<T, D>>::type * = nullptr>
constexpr auto operator()(D const &d) const
-> decltype(static_cast<T const *>(std::addressof(d)))
{
return static_cast<T const *>(std::addressof(d));
}

template <typename B, typename std::enable_if<!viaGetIfV<T, B> && std::is_base_of_v<B, T>>::type * = nullptr>
constexpr auto operator()(B const &b) const
-> decltype(dynamic_cast<T const *>(std::addressof(b)))
Expand Down
11 changes: 11 additions & 0 deletions test/matchit/legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ TEST(Match, test10)
EXPECT_EQ(dynCast(std::unique_ptr<Shape>()), "None");
}

TEST(Match, test10_)
{
auto const dToBCast = [](auto const &i)
{
return match(i)(pattern | some(as<Shape>(_)) = expr("Shape"),
pattern | none = expr("None"));
};

EXPECT_EQ(dToBCast(std::make_unique<Circle>()), "Shape");
}

TEST(Match, test11)
{
auto const getIf = [](auto const &i)
Expand Down

0 comments on commit cb68c92

Please sign in to comment.