Skip to content
Snippets Groups Projects
Commit a771892c authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Add Number concept in terms of IsNumber

parent fa579ea1
Branches
No related tags found
1 merge request!1493Add Number concept in terms of IsNumber
Pipeline #75718 waiting for manual action
......@@ -25,6 +25,8 @@ SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
- Add deduction guides to `TupleVector` analogous to `std::tuple`.
- Add concept definition `Concept::Number` to represent scalar number types in containers.
## Build system: Changelog
- Add a module-specific CMake target `build_<module>_tests` to compile only tests
......
......@@ -4,4 +4,5 @@
install(FILES
container.hh
hashable.hh
number.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/common/concepts)
// 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_NUMBER_HH
#define DUNE_COMMON_CONCEPTS_NUMBER_HH
#include <dune/common/typetraits.hh>
namespace Dune::Concept {
/**
* \brief The `Number` concept is satisfied if the type `N` can act as a scalar
* in the context of (hierarchically blocked) containers.
*
* Number types are possible element types of (hierarchically blocked) matrices
* and vectors, such as `FieldMatrix`, `FieldVector`, `BCRSMatrix`, `BlockVector`,
* `MultiTypeBlockVector`, etc. It allows, for example, to define break conditions
* in recursive algorithms and are used as value initializers and scalar factors
* in scaling operations.
*
* Types that can act as number types include the arithmetic types like `double`,
* `int`, or `float`, and the `std::complex<U>` types if `U` itself is a scalar
* type. It is possible to register used-defined types, e.g., extended precision
* types or automatic differentiation types, or anything else that might sensibly
* be an element of a matrix or vector. Therefore, the traits class `Dune::IsNumber`
* can be specialized.
*
* \note The precise semantics of number types are only vaguely specified. It
* should behave similar to arithmetic types, e.g., provide arithmetic operations,
* and should be considered a field type in the mathematical sense.
*/
template <class N>
concept Number = Dune::IsNumber<N>::value;
} // end namespace Dune::Concept
#endif // DUNE_COMMON_CONCEPTS_NUMBER_HH
......@@ -2,26 +2,26 @@
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#include <dune/common/concepts.hh>
#if DUNE_ENABLE_CONCEPTS
#include <array>
#include <bitset>
#include <complex>
#include <list>
#include <type_traits>
#include <vector>
#include <dune/common/bigunsignedint.hh>
#include <dune/common/fvector.hh>
#include <dune/common/gmpfield.hh>
#include <dune/common/hash.hh>
#include <dune/common/quadmath.hh>
#include <dune/common/reservedvector.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/concepts/container.hh>
#include <dune/common/concepts/hashable.hh>
#include <dune/common/concepts/number.hh>
int main (int argc, char **argv)
int main ()
{
using namespace Dune;
MPIHelper::instance(argc, argv);
// test Hashable
static_assert(Concept::Hashable<int>);
......@@ -39,10 +39,30 @@ int main (int argc, char **argv)
static_assert(not Concept::Container<double*>);
static_assert(not Concept::Container<Dune::FieldVector<double,3>>);
}
#else // DUNE_ENABLE_CONCEPTS
// test Number concept for arithmetic types
static_assert(Concept::Number<short>);
static_assert(Concept::Number<unsigned short>);
static_assert(Concept::Number<int>);
static_assert(Concept::Number<unsigned int>);
static_assert(Concept::Number<long>);
static_assert(Concept::Number<unsigned long>);
int main () { return 77; }
static_assert(Concept::Number<float>);
static_assert(Concept::Number<double>);
static_assert(Concept::Number<long double>);
#endif // DUNE_ENABLE_CONCEPTS
static_assert(Concept::Number<std::complex<float>>);
static_assert(Concept::Number<std::complex<double>>);
static_assert(Concept::Number<std::complex<long double>>);
// test Number concept for user-defined types
static_assert(Concept::Number<Dune::bigunsignedint<64>>);
#if HAVE_GMP
static_assert(Concept::Number<Dune::GMPField<64>>);
#endif
#if HAVE_QUADMATH
static_assert(Concept::Number<Dune::Float128>);
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment