Skip to content

Commit cb68c92

Browse files
authored
Add D to B cast. (#66)
* Add D to B cast. * parallel 4. Co-authored-by: Bowen Fu <missing>
1 parent 8e82b24 commit cb68c92

File tree

7 files changed

+29
-4
lines changed

7 files changed

+29
-4
lines changed

.github/workflows/cmake.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ jobs:
3939
working-directory: ${{github.workspace}}/build
4040
# Execute tests defined by the CMake configuration.
4141
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
42-
run: ctest --output-on-failure -C ${{env.BUILD_TYPE}}
42+
run: ctest --output-on-failure --parallel 4 -C ${{env.BUILD_TYPE}}
4343

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
working-directory: ${{github.workspace}}/build
4343
# Execute tests defined by the CMake configuration.
4444
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
45-
run: ctest --output-on-failure -C ${{env.BUILD_TYPE}}
45+
run: ctest --output-on-failure --parallel 4 -C ${{env.BUILD_TYPE}}
4646

4747
- name: Compute Coverage
4848
working-directory: ${{github.workspace}}/build

.github/workflows/sanitizers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ jobs:
4242
working-directory: ${{github.workspace}}/build
4343
# Execute tests defined by the CMake configuration.
4444
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
45-
run: ctest --output-on-failure -C ${{ matrix.build_type }}
45+
run: ctest --output-on-failure --parallel 4 -C ${{ matrix.build_type }}
4646

.github/workflows/valgrind.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343
# Execute tests defined by the CMake configuration.
4444
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
4545
run: |
46-
ctest --output-on-failure -C ${{env.BUILD_TYPE}} --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=100" -T memcheck
46+
ctest --output-on-failure --parallel 4 -C ${{env.BUILD_TYPE}} --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=100" -T memcheck
4747
# --overwrite MemoryCheckSuppressionFile=/path/to/valgrind.suppressions \
4848

develop/matchit/utility.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ namespace matchit
5959
return std::any_cast<T>(std::addressof(a));
6060
}
6161

62+
template <typename D, typename std::enable_if<!viaGetIfV<T, D> && std::is_base_of_v<T, D>>::type * = nullptr>
63+
constexpr auto operator()(D const &d) const
64+
-> decltype(static_cast<T const *>(std::addressof(d)))
65+
{
66+
return static_cast<T const *>(std::addressof(d));
67+
}
68+
6269
template <typename B, typename std::enable_if<!viaGetIfV<T, B> && std::is_base_of_v<B, T>>::type * = nullptr>
6370
constexpr auto operator()(B const &b) const
6471
-> decltype(dynamic_cast<T const *>(std::addressof(b)))

include/matchit.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,13 @@ namespace matchit
19911991
return std::any_cast<T>(std::addressof(a));
19921992
}
19931993

1994+
template <typename D, typename std::enable_if<!viaGetIfV<T, D> && std::is_base_of_v<T, D>>::type * = nullptr>
1995+
constexpr auto operator()(D const &d) const
1996+
-> decltype(static_cast<T const *>(std::addressof(d)))
1997+
{
1998+
return static_cast<T const *>(std::addressof(d));
1999+
}
2000+
19942001
template <typename B, typename std::enable_if<!viaGetIfV<T, B> && std::is_base_of_v<B, T>>::type * = nullptr>
19952002
constexpr auto operator()(B const &b) const
19962003
-> decltype(dynamic_cast<T const *>(std::addressof(b)))

test/matchit/legacy.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ TEST(Match, test10)
255255
EXPECT_EQ(dynCast(std::unique_ptr<Shape>()), "None");
256256
}
257257

258+
TEST(Match, test10_)
259+
{
260+
auto const dToBCast = [](auto const &i)
261+
{
262+
return match(i)(pattern | some(as<Shape>(_)) = expr("Shape"),
263+
pattern | none = expr("None"));
264+
};
265+
266+
EXPECT_EQ(dToBCast(std::make_unique<Circle>()), "Shape");
267+
}
268+
258269
TEST(Match, test11)
259270
{
260271
auto const getIf = [](auto const &i)

0 commit comments

Comments
 (0)