3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
isvalid.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_TYPETRAITS_ISVALID_HH
27#define DUMUX_TYPETRAITS_ISVALID_HH
28
29#include <type_traits>
30
31namespace Dumux {
32
33namespace Detail {
34
35// the functor testing an expression for validity
36// Expression: can be for example a lambda expression
37template <typename Expression>
39{
40private:
41 // std::declval creates an object of expression
42 // the expression, i.e. a lambda expression gets an object as a parameter and does checks on it.
43 // so we create also an object of the parameter usiung std::declval
44 // if decltype can evaluate the type, i.e. the object parameter is a valid argument for the expression
45 // we return std::true_type
46 // note: the int is used to give the first overload always precedence
47 // note: the last argument in decltype determines the deduced type but all types need to be valid
48 template <typename Argument>
49 constexpr auto testArgument_(int /* unused int to make this overload the priority choice */) const
50 -> decltype(std::declval<Expression>()(std::declval<Argument>()), std::true_type())
51 { return std::true_type(); }
52
53 // otherwise we return std::false_type, i.e. this is the fallback
54 template <typename Argument>
55 constexpr std::false_type testArgument_(...) const
56 { return std::false_type(); }
57
58public:
59 // the operator () takes the argument we want to use as argument to the test expression
60 // note we use the int to prefer the "valid"-result overload of test_ if possible
61 template <typename Argument>
62 constexpr auto operator() (const Argument& arg) const
63 { return testArgument_<Argument>(int()); }
64
65 // check function takes the template argument explicitly
66 template <typename Argument>
67 constexpr auto check () const
68 { return testArgument_<Argument>(int()); }
69};
70
71} // end namespace Detail
72
73
92template <typename Expression>
93constexpr auto isValid(const Expression& t)
95
96} // end namespace Dumux
97
98#endif
Definition: adapt.hh:29
constexpr auto isValid(const Expression &t)
A function that creates a test functor to do class member introspection at compile time.
Definition: isvalid.hh:93
Definition: isvalid.hh:39
constexpr auto operator()(const Argument &arg) const
Definition: isvalid.hh:62
constexpr auto check() const
Definition: isvalid.hh:67