DUNE PDELab (git)

container.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_COMMON_CONCEPTS_CONTAINER_HH
6#define DUNE_COMMON_CONCEPTS_CONTAINER_HH
7
8// check whether c++20 concept can be used
9#if __has_include(<version>) && __has_include(<concepts>)
10 #include <version>
11 #if __cpp_concepts >= 201907L && __cpp_lib_concepts >= 202002L
12 #ifndef DUNE_ENABLE_CONCEPTS
13 #define DUNE_ENABLE_CONCEPTS 1
14 #endif
15 #endif
16#endif
17
18#if DUNE_ENABLE_CONCEPTS
19
20#include <concepts>
21#include <iterator>
22
23#if __has_include(<ranges>)
24#include <ranges>
25#endif
26
27namespace Dune::Concept {
28
57template<class T>
58concept Container =
59 std::regular<T> &&
60 std::swappable<T> &&
61#if __has_include(<ranges>)
62 std::ranges::range<T> &&
63#endif
64requires(T a, const T ca)
65{
66 typename T::value_type;
67 requires std::unsigned_integral<typename T::size_type>;
68 requires std::forward_iterator<typename T::iterator>;
69 requires std::forward_iterator<typename T::const_iterator>;
70 { a.begin() } -> std::same_as<typename T::iterator>;
71 { a.end() } -> std::same_as<typename T::iterator>;
72 { ca.begin() } -> std::same_as<typename T::const_iterator>;
73 { ca.end() } -> std::same_as<typename T::const_iterator>;
74 { a.cbegin() } -> std::same_as<typename T::const_iterator>;
75 { a.cend() } -> std::same_as<typename T::const_iterator>;
76 { a.size() } -> std::same_as<typename T::size_type>;
77 { a.max_size() } -> std::same_as<typename T::size_type>;
78 { a.empty() } -> std::convertible_to<bool>;
79};
80
103template<class T>
104concept RandomAccessContainer =
105 Container<T> &&
106#if __has_include(<ranges>)
107 std::ranges::random_access_range<T> &&
108#endif
109requires(T a, const T ca, typename T::size_type i)
110{
111 requires std::same_as<typename T::reference, typename T::value_type&>;
112 requires std::same_as<typename T::const_reference, const typename T::value_type&>;
113 requires std::random_access_iterator<typename T::iterator>;
114 requires std::random_access_iterator<typename T::const_iterator>;
115 { a[i] } -> std::same_as<typename T::reference>;
116 { ca[i] } -> std::same_as<typename T::const_reference>;
117};
118
119} // end namespace Dune::Concept
120
121#endif // DUNE_ENABLE_CONCEPTS
122
123#endif // DUNE_COMMON_CONCEPTS_CONTAINER_HH
Namespace for concepts.
Definition: concept.hh:34
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)