magnitude.hpp 2.08 KB
Newer Older
1
// Software License for MTL
2
//
3
4
5
6
7
// Copyright (c) 2007 The Trustees of Indiana University.
//               2008 Dresden University of Technology and the Trustees of Indiana University.
//               2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
8
//
9
// This file is part of the Matrix Template Library
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// See also license.mtl.txt in the distribution.

#ifndef MTL_MAGNITUDE_INCLUDE
#define MTL_MAGNITUDE_INCLUDE

#include <complex>

namespace mtl {

// =================================================
// Concept to specify return type of abs (and norms)
// =================================================


#ifdef __GXX_CONCEPTS__

// Concept to specify to specify projection of scalar value to comparable type
// For instance as return type of abs
// Minimalist definition for maximal applicability
auto concept Magnitude<typename T>
{
    typename type = T;
};

template <typename T>
concept_map Magnitude<std::complex<T> >
{
    typedef T type;
}


// Concept for norms etc., which are real values in mathematical definitions
auto concept RealMagnitude<typename T>
  : Magnitude<T>
{
    requires std::EqualityComparable<type>;
    requires std::LessThanComparable<type>;

#ifndef CONCEPTS_WITHOUT_OVERLOADED_REQUIREMENTS
    requires Field<type>;
#endif

    type sqrt(type);

    type abs(T);
}

#else  // now without concepts

/// Concept/Type-trait for magnitudes of scalar values
/** This name is overloaded: when MTL4 is compiled with a concept-compiler
    Magnitude is a concept otherwise a type-trait.
63
    It is used for instance in norms.
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
**/
template <typename T>
struct Magnitude
{
    /// Associated type; the default is T; must be specialized appropriately
    typedef T type;
};

/// Specialization for complex numbers
template <typename T>
struct Magnitude<std::complex<T> >
{
    /// The associated type is defined to the complex's value type
    typedef T type;
};

template <typename T> struct RealMagnitude
  : public Magnitude<T>
{};

#endif  // __GXX_CONCEPTS__

} // namespace mtl

#endif // MTL_MAGNITUDE_INCLUDE