File: conditional.hh

package info (click to toggle)
dune-common 2.11.0-1~exp2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 6,056 kB
  • sloc: cpp: 54,404; python: 4,136; sh: 1,657; makefile: 17
file content (35 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_CONDITIONAL_HH
#define DUNE_COMMON_CONDITIONAL_HH

namespace Dune
{

    /** \brief conditional evaluate

        sometimes call immediate if, evaluates to

        \code
        if (b)
           return v1;
        else
           return v2;
        \endcode

        In contrast to if-then-else the cond function can also be
        evaluated for vector valued SIMD data types, see simd.hh.

        \param b boolean value
        \param v1 value of b==true
        \param v2 value of b==false
    */
    template<typename T1, typename T2>
    const T1 cond(bool b, const T1 & v1, const T2 & v2)
    {
        return (b ? v1 : v2);
    }

} // end namespace Dune

#endif // DUNE_COMMON_CONDITIONAL_HH