Skip to content
Snippets Groups Projects
Commit 5b636ee9 authored by Carsten Gräser's avatar Carsten Gräser
Browse files

Improve specializations of Hybrid::size()

The interfaces tested subsequently for `Hybrid::size(const T& t)` are now

* standard tuple-like interface `std::tuple_size<T>::value` (e.g. needed for `std::tuple`),
* static constexpr `T::size()` (e.g. needed for `Dune::TupleVector`),
* static constexpr `T::N()` (e.g. needed for `Dune::MultiTypeBlockMatrix`),
* dynamic member function `t.N()` (e.g. needed for `Dune::Matrix`),
* dynamic member function `t.size()` (e.g. needed for `std::vector`).

Unfortunately the matrix interface is rather inconsistent.
While `Dune::DenseMatrix` provides a dyanmic `size()` method, the dynamic dense matrix
`Dune::Matrix` does not. The only consistent interface to get the number of rows is the
`N()` method which exists in dynamic (e.g. `Dune::Matrix`) and constexpr static
(e.g. `Dune::MultiTypeBlockMatrix`) flavour.
Hence to support matrices consistently, we must add support for those cases, too.

For the static constexpr `N()`, this was made neccessary, because of the removal of
static consexpr `Dune::MultiTypeBlockMatrix::size()`. The dynamic case should be
added for consistency to also support `Dune::Matrix` and `Dune::BCRSMatrix`.
As a by-product, this allows to get rid of the `FieldMatrix` specialization.
parent 058f0c44
No related branches found
No related tags found
No related merge requests found
Pipeline #55986 passed
Pipeline: Dune Nightly Test

#55987

    ......@@ -23,30 +23,38 @@ namespace Hybrid {
    namespace Impl {
    // Try if tuple_size is implemented for class
    template<class T, int i>
    constexpr auto size(const Dune::FieldVector<T, i>&, const PriorityTag<5>&)
    -> decltype(std::integral_constant<std::size_t,i>())
    template<class T>
    constexpr auto size(const T&, const PriorityTag<4>&)
    -> decltype(std::integral_constant<std::size_t,std::tuple_size<T>::value>())
    {
    return {};
    }
    // Try if tuple_size is implemented for class
    // Try if there's a static constexpr size()
    template<class T>
    constexpr auto size(const T&, const PriorityTag<3>&)
    -> decltype(std::integral_constant<std::size_t,std::tuple_size<T>::value>())
    -> decltype(std::integral_constant<std::size_t,T::size()>())
    {
    return {};
    }
    // Try if there's a static constexpr size()
    // Try if there's a static constexpr N()
    template<class T>
    constexpr auto size(const T&, const PriorityTag<1>&)
    -> decltype(std::integral_constant<std::size_t,T::size()>())
    constexpr auto size(const T&, const PriorityTag<2>&)
    -> decltype(std::integral_constant<std::size_t,T::N()>())
    {
    return {};
    }
    // As a last resort try if there's a static constexpr size()
    // Try if there's a non-static N()
    template<class T>
    constexpr auto size(const T& t, const PriorityTag<1>&)
    -> decltype(t.N())
    {
    return t.N();
    }
    // As a last resort try if there's a non-static size()
    template<class T>
    constexpr auto size(const T& t, const PriorityTag<0>&)
    {
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment