Loading...
Searching...
No Matches
container.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_COMMON_CONCEPTS_CONTAINER_HH
#define DUNE_COMMON_CONCEPTS_CONTAINER_HH
// check whether c++20 concept can be used
#if __has_include(<version>) && __has_include(<concepts>)
#include <version>
#if __cpp_concepts >= 201907L && __cpp_lib_concepts >= 202002L
#ifndef DUNE_ENABLE_CONCEPTS
#define DUNE_ENABLE_CONCEPTS 1
#endif
#endif
#endif
#if DUNE_ENABLE_CONCEPTS
#include <concepts>
#include <iterator>
namespace Dune::Concept {
template<class T>
concept Container =
std::regular<T> &&
std::swappable<T> &&
requires(T a, const T ca)
{
typename T::value_type;
requires std::unsigned_integral<typename T::size_type>;
requires std::forward_iterator<typename T::iterator>;
requires std::forward_iterator<typename T::const_iterator>;
{ a.begin() } -> std::same_as<typename T::iterator>;
{ a.end() } -> std::same_as<typename T::iterator>;
{ ca.begin() } -> std::same_as<typename T::const_iterator>;
{ ca.end() } -> std::same_as<typename T::const_iterator>;
{ a.cbegin() } -> std::same_as<typename T::const_iterator>;
{ a.cend() } -> std::same_as<typename T::const_iterator>;
{ a.size() } -> std::same_as<typename T::size_type>;
{ a.max_size() } -> std::same_as<typename T::size_type>;
{ a.empty() } -> std::convertible_to<bool>;
};
template<class T>
concept RandomAccessContainer =
Container<T> &&
requires(T a, const T ca, typename T::size_type i)
{
requires std::same_as<typename T::reference, typename T::value_type&>;
requires std::same_as<typename T::const_reference, const typename T::value_type&>;
requires std::random_access_iterator<typename T::iterator>;
requires std::random_access_iterator<typename T::const_iterator>;
{ a[i] } -> std::same_as<typename T::reference>;
{ ca[i] } -> std::same_as<typename T::const_reference>;
};
} // end namespace Dune::Concept
#endif // DUNE_ENABLE_CONCEPTS
#endif // DUNE_COMMON_CONCEPTS_CONTAINER_HH
Dune::Concept
Namespace for concepts.
Definition concept.hh:33