// ------------------------------------------------------------------------ // // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (C) 2003 - 2025 by the deal.II authors // // This file is part of the deal.II library. // // Part of the source code is dual licensed under Apache-2.0 WITH // LLVM-exception OR LGPL-2.1-or-later. Detailed license information // governing the source code and code contributions can be found in // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. // // ------------------------------------------------------------------------ #ifndef dealii_template_constraints_h #define dealii_template_constraints_h #include #include #include #include #include #include #include DEAL_II_NAMESPACE_OPEN // Detection idiom adapted from Version 2 of the C++ Extensions for Library // Fundamentals, ISO/IEC TS 19568:2017 namespace internal { /** * A namespace used to declare the machinery for detecting whether a specific * class supports an operation. This approach simulates C++20-style * concepts with language standards before C++20. */ namespace SupportsOperation { template using void_t = void; /** * The primary template class used in detecting operations. If the * compiler does not choose the specialization, then the fall-back * case is this general template, which then declares member variables * and types according to the failed detection. */ template class Op, class... Args> struct detector { using value_t = std::false_type; using type = Default; }; /** * A specialization of the general template. * * The trick this class uses is that, just like the general template, * its second argument is always `void`, but here it is written as * `void_t>` and consequently the compiler will only select this * specialization if `Op` is in fact a valid type. This means that * the operation we seek to understand is indeed supported. * * This specialization then declares member variables and types according * to the successful detection. */ template class Op, class... Args> struct detector>, Op, Args...> { using value_t = std::true_type; using type = Op; }; /** * A base class for the `nonesuch` type to inherit from so it is not an * aggregate. */ struct nonesuch_base {}; /** * A type that can not be used in any reasonable way and consequently * can be used to indicate a failed detection in template metaprogramming. */ struct nonesuch : private nonesuch_base { ~nonesuch() = delete; nonesuch(const nonesuch &) = delete; void operator=(const nonesuch &) = delete; }; template class Op, class... Args> using detected_or = detector; template