From f0a290ea1f40e42cba7cbe4d49f3ab5730f9c770 Mon Sep 17 00:00:00 2001 From: Thomas Spriggs Date: Tue, 14 Nov 2023 14:25:52 +0000 Subject: [PATCH] Use `if constexpr` in `smt_function_application_termt::indices` With C++17's `if constexpr` feature we can now remove two alternate function templates and just put the alternate implementations in line. This puts the specialisation into the outer function, so that it is specialised with the correct implementation for the given `functiont`, rather than dispatching based on the `std::true_type` / `std::false_type` overloads. --- src/solvers/smt2_incremental/ast/smt_terms.h | 25 +++++--------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/solvers/smt2_incremental/ast/smt_terms.h b/src/solvers/smt2_incremental/ast/smt_terms.h index c8b2d375a37..eef3b3dbb0f 100644 --- a/src/solvers/smt2_incremental/ast/smt_terms.h +++ b/src/solvers/smt2_incremental/ast/smt_terms.h @@ -153,28 +153,15 @@ class smt_function_application_termt : public smt_termt { }; - /// Overload for when \p functiont does not have indices. - template - static std::vector - indices(const functiont &function, const std::false_type &has_indices) - { - return {}; - } - - /// Overload for when \p functiont has indices member function. - template - static std::vector - indices(const functiont &function, const std::true_type &has_indices) - { - return function.indices(); - } - - /// Returns `function.indices` if `functiont` has an `indices` member function - /// or returns an empty collection otherwise. + /// Returns `function.indices()` if `functiont` has an `indices` member + /// function or returns an empty collection otherwise. template static std::vector indices(const functiont &function) { - return indices(function, has_indicest{}); + if constexpr(has_indicest::value) + return function.indices(); + else + return {}; } public: