version 3.11-dev
Loading...
Searching...
No Matches
deprecated.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12
13#ifndef DUMUX_COMMON_DEPRECATED_HH
14#define DUMUX_COMMON_DEPRECATED_HH
15
16#include <utility>
17#include <ranges>
18#include <type_traits>
19
20#include <dune/common/ftraits.hh>
21#include <dune/common/exceptions.hh>
22#include <dune/common/std/type_traits.hh>
24
25namespace Dumux {
26
27#ifndef DOXYGEN // hide from doxygen
28// Helper classes/functions for deprecation
29// Each implementation has to state after which release
30// it will be removed. Implementations in the Deprecated
31// namespace will be removed without
32// deprecation after their usage in the code expired,
33// so most likely you don't want to use this in your code
34namespace Deprecated {
35
36#ifdef __clang__
37#pragma clang diagnostic push
38#pragma clang diagnostic ignored "-Wdeprecated-declarations"
39#endif // __clang__
40
41#ifdef __clang__
42#pragma clang diagnostic pop
43#endif // __clang__
44
45// Helper concept detecting new interface.
46// Remove after release 3.11
47template<class GG, class GI>
48concept hasRangeOfPeriodicallyMappedDofs = requires (GG gg, GI gi) {
49 { gg.periodicallyMappedDofs(gi) } -> std::ranges::range;
50};
51
52// helper function triggering deprecation warning if grid geometry does not implement new interface or program uses old interface.
53// Remove after release 3.11
54template<class Dof>
55[[deprecated("The periodicDofMap with values of single periodic dofs will not be supported after release 3.11. Use/define in custom grid geometry a periodicDofMap with a range of dofs as value type, as well as accessor periodicallyMappedDofs returning a std::views::all/single of the storage if possible")]]
56inline const std::ranges::range auto wrapSinglePeriodicDof(const Dof& dof)
57{
58 return std::ranges::views::single(dof);
59}
60
61// Helper function to access values from map of periodic dofs, viewing stored ranges instead of copying them.
62// Remove after release 3.11
63template<class T> requires std::ranges::range<T>
64inline std::ranges::range auto ensureRangeOfPeriodicDofs(T&& range)
65{
66 if constexpr (std::is_lvalue_reference_v<T> || std::ranges::view<std::remove_cvref_t<T>>)
67 return std::views::all(std::forward<T>(range));
68 else
69 return std::remove_cvref_t<T>(std::forward<T>(range));
70}
71
72template<typename T> requires (!std::ranges::range<T>)
73inline const std::ranges::range auto ensureRangeOfPeriodicDofs(const T& entry)
74{ return wrapSinglePeriodicDof(entry); }
75
76// Helper functions to access ranges of periodically mapped dofs through common interface.
77// Remove after release 3.11
78template<class GG, class GI>
79inline const std::ranges::range auto rangeOfPeriodicallyMappedDofs(const GG& gg, const GI& gi)
80{
81 if constexpr (hasRangeOfPeriodicallyMappedDofs<GG, GI>)
82 return ensureRangeOfPeriodicDofs(gg.periodicallyMappedDofs(gi));
83 else
84 return wrapSinglePeriodicDof(gg.periodicallyMappedDof(gi));
85}
86
87} // end namespace Deprecated
88#endif
89
90} // end namespace Dune
91#endif
Definition adapt.hh:17
A helper to deduce a vector with the same size as numbers of equations.