basic.hpp 2.95 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
20
21
22
23
24
25
26
27
 ******************************************************************************/



/** \file basic.hpp */

#ifndef AMDIS_BASIC_TRAITS_HPP
#define AMDIS_BASIC_TRAITS_HPP

28
#include <boost/version.hpp>
29
30
31
32
33
34
35
36
37
#include <boost/mpl/logical.hpp>

#include "boost/numeric/ublas/detail/returntype_deduction.hpp"
#if BOOST_VERSION >= 105600
#include <boost/core/enable_if.hpp>
#else
#include <boost/utility/enable_if.hpp>
#endif

38
#ifdef HAS_CXX11
39
40
41
#include <type_traits>
#endif

42
namespace AMDiS
43
44
45
46
{

  // introduce some shortcuts for boost::mpl
  // ---------------------------------------
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

#ifdef HAS_CXX11
  template <bool B>
  using bool_ = std::integral_constant<bool, B>;

  using true_ = bool_<true>;
  using false_ = bool_<false>;

  namespace aux
  {
    template <class... Ts> struct or_;

    template <class T0, class... Ts>
    struct or_<T0, Ts...> : bool_<T0::value || or_<Ts...>::value> {};

    template <>
    struct or_<> : false_ {};

    template <class... Ts> struct and_;

    template <class T0, class... Ts>
    struct and_<T0, Ts...> : bool_<T0::value && and_<Ts...>::value> {};

    template <>
    struct and_<> : true_ {};

  } // end namespace aux


  template <class... Ts>
  using and_ = aux::and_<Ts...>;

  template <class... Ts>
  using or_ = aux::or_<Ts...>;

  template <class A>
  using not_ = bool_<!(A::value)>;

#else
86
  using boost::mpl::bool_;
87
88
89
90
  using boost::mpl::true_;
  using boost::mpl::false_;
  using boost::mpl::and_;
  using boost::mpl::or_;
91
92
  using boost::mpl::not_;
#endif
93

94
  using boost::enable_if;
95
  using boost::enable_if_c;
96
  using boost::disable_if;
97
  using boost::disable_if_c;
98
99
100
101
102

  template <class T>
  struct id {};

  namespace traits
103
  {
104

105
106
    // dummy type
    typedef boost::numeric::ublas::error_cant_deduce_type no_valid_type;
107

108
    template <class A, class B>
109
110
    struct is_multiplicable : boost::mpl::not_<
	boost::is_same< typename mtl::Multiplicable<A,B>::result_type,
111
		        no_valid_type > > {};
112

113
    template <class A, class B>
114
115
    struct is_addable : boost::mpl::not_<
	boost::is_same< typename mtl::Addable<A,B>::result_type,
116
			no_valid_type > > {};
117

118
119
    template <typename T>
    struct is_trivially_copyable : boost::is_pod<T> {};
120

121
122
    template <class T, T A, T B>
    struct equal : boost::mpl::if_c< A == B, true_, false_ > {};
123
  }
124
125

//   template <class T>
126
//   T zero(T result) { result = 0; return result; }
127
128
129
130
}


#endif // AMDIS_BASIC_TRAITS_HPP