version 3.8.0
Loading...
Searching...
No Matches
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
// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5
// SPDX-License-Identifier: GPL-3.0-or-later
6
//
14
#ifndef DUMUX_TYPETRAITS_ISVALID_HH
15
#define DUMUX_TYPETRAITS_ISVALID_HH
16
17
#include <type_traits>
18
19
namespace
Dumux
{
20
21
namespace
Detail {
22
23
// the functor testing an expression for validity
24
// Expression: can be for example a lambda expression
25
template
<
typename
Expression>
26
struct
ValidityTestFunctor
27
{
28
private
:
29
// std::declval creates an object of expression
30
// the expression, i.e. a lambda expression gets an object as a parameter and does checks on it.
31
// so we create also an object of the parameter usiung std::declval
32
// if decltype can evaluate the type, i.e. the object parameter is a valid argument for the expression
33
// we return std::true_type
34
// note: the int is used to give the first overload always precedence
35
// note: the last argument in decltype determines the deduced type but all types need to be valid
36
template
<
typename
Argument>
37
constexpr
auto
testArgument_(
int
/* unused int to make this overload the priority choice */
)
const
38
->
decltype
(std::declval<Expression>()(std::declval<Argument>()), std::true_type())
39
{
return
std::true_type(); }
40
41
// otherwise we return std::false_type, i.e. this is the fallback
42
template
<
typename
Argument>
43
constexpr
std::false_type testArgument_(...)
const
44
{
return
std::false_type(); }
45
46
public
:
47
// the operator () takes the argument we want to use as argument to the test expression
48
// note we use the int to prefer the "valid"-result overload of test_ if possible
49
template
<
typename
Argument>
50
constexpr
auto
operator()
(
const
Argument& arg)
const
51
{
return
testArgument_<Argument>(
int
()); }
52
53
// check function takes the template argument explicitly
54
template
<
typename
Argument>
55
constexpr
auto
check
()
const
56
{
return
testArgument_<Argument>(
int
()); }
57
};
58
59
}
// end namespace Detail
60
61
80
template
<
typename
Expression>
81
constexpr
auto
isValid
(
const
Expression& t)
82
{
return
Detail::ValidityTestFunctor<Expression>
(); }
83
84
}
// end namespace Dumux
85
86
#endif
Dumux::isValid
constexpr auto isValid(const Expression &t)
A function that creates a test functor to do class member introspection at compile time.
Definition
isvalid.hh:81
Dumux
Definition
adapt.hh:17
Dumux::Detail::ValidityTestFunctor
Definition
isvalid.hh:27
Dumux::Detail::ValidityTestFunctor::operator()
constexpr auto operator()(const Argument &arg) const
Definition
isvalid.hh:50
Dumux::Detail::ValidityTestFunctor::check
constexpr auto check() const
Definition
isvalid.hh:55
dumux
common
typetraits
isvalid.hh
© Copyright 2010-
DuMux project contributors
(doc pages:
CC-BY 4.0
/ code examples:
GPLv3 or later
)
3.8.0 Generated by
1.9.8