00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_STD_CONCEPT_INCLUDE
00013 #define MTL_STD_CONCEPT_INCLUDE
00014
00015 #ifdef __GXX_CONCEPTS__
00016 # include <concepts>
00017 #else
00018
00019 # include <boost/numeric/ublas/detail/returntype_deduction.hpp>
00020 # include <boost/mpl/at.hpp>
00021 # include <boost/numeric/linear_algebra/pseudo_concept.hpp>
00022 #endif
00023
00024 namespace mtl {
00025
00030
00031 #ifdef __GXX_CONCEPTS__
00032
00033
00034
00035 auto concept Addable<typename T, typename U = T> : std::HasPlus<T, U> {}
00036 auto concept Subtractable<typename T, typename U = T> : std::HasMinus<T, U> {}
00037 auto concept Multiplicable<typename T, typename U = T> : std::HasMultiply<T, U> {}
00038 auto concept Divisible<typename T, typename U = T> : std::HasDivide<T, U> {}
00039
00040 #if 0
00041 using std::Addable;
00042 using std::Subtractable;
00043 using std::Multiplicable;
00044
00045 auto concept Divisible<typename T, typename U = T>
00046 {
00047 typename result_type;
00048 result_type operator/(const T& t, const U& u);
00049 };
00050 #endif
00051
00052 #else // without concepts
00053
00054
00055
00056
00057
00058
00059
00061
00062 template<class X, class Y>
00063 class Addable
00064 {
00065 typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
00066 static typename base_type::x_type x;
00067 static typename base_type::y_type y;
00068 static const std::size_t size = sizeof (
00069 boost::numeric::ublas::type_deduction_detail::test<
00070 typename base_type::x_type
00071 , typename base_type::y_type
00072 >(x + y)
00073 );
00074
00075 static const std::size_t index = (size / sizeof (char)) - 1;
00076 typedef typename boost::mpl::at_c<
00077 typename base_type::types, index>::type id;
00078 public:
00080 typedef typename id::type result_type;
00081 };
00082
00083
00085
00086 template<class X, class Y>
00087 class Subtractable
00088 {
00089 typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
00090 static typename base_type::x_type x;
00091 static typename base_type::y_type y;
00092 static const std::size_t size = sizeof (
00093 boost::numeric::ublas::type_deduction_detail::test<
00094 typename base_type::x_type
00095 , typename base_type::y_type
00096 >(x - y)
00097 );
00098
00099 static const std::size_t index = (size / sizeof (char)) - 1;
00100 typedef typename boost::mpl::at_c<
00101 typename base_type::types, index>::type id;
00102 public:
00104 typedef typename id::type result_type;
00105 };
00106
00108
00109 template<class X, class Y>
00110 class Multiplicable
00111 {
00112 typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
00113 static typename base_type::x_type x;
00114 static typename base_type::y_type y;
00115 static const std::size_t size = sizeof (
00116 boost::numeric::ublas::type_deduction_detail::test<
00117 typename base_type::x_type
00118 , typename base_type::y_type
00119 >(x * y)
00120 );
00121
00122 static const std::size_t index = (size / sizeof (char)) - 1;
00123 typedef typename boost::mpl::at_c<
00124 typename base_type::types, index>::type id;
00125 public:
00127 typedef typename id::type result_type;
00128 };
00129
00131
00132 template<class X, class Y>
00133 class Divisible
00134 {
00135 typedef boost::numeric::ublas::type_deduction_detail::base_result_of<X, Y> base_type;
00136 static typename base_type::x_type x;
00137 static typename base_type::y_type y;
00138 static const std::size_t size = sizeof (
00139 boost::numeric::ublas::type_deduction_detail::test<
00140 typename base_type::x_type
00141 , typename base_type::y_type
00142 >(x * y)
00143 );
00144
00145 static const std::size_t index = (size / sizeof (char)) - 1;
00146 typedef typename boost::mpl::at_c<
00147 typename base_type::types, index>::type id;
00148 public:
00150 typedef typename id::type result_type;
00151 };
00152
00153 #endif
00154
00155
00156 #ifdef __GXX_CONCEPTS__
00157 concept UnaryStaticFunctor<typename F, typename T>
00158 : std::Callable1<F, T>
00159 {
00160 typename result_type;
00161
00162 static result_type F::apply(T);
00163 };
00164 #else
00165
00166
00167 template <typename T>
00168 struct UnaryFunctor
00169 {
00171 typedef associated_type result_type;
00172
00174 result_type operator()(T);
00175 };
00176
00177
00179
00183 template <typename T>
00184 struct UnaryStaticFunctor
00185 : public UnaryFunctor<T>
00186 {
00188 typedef associated_type result_type;
00189
00191 static result_type apply(T);
00192
00194 result_type operator()(T);
00195 };
00196 #endif
00197
00198
00199 #ifdef __GXX_CONCEPTS__
00200 auto concept BinaryStaticFunctor<typename F, typename T, typename U>
00201 : std::Callable2<F, T, U>
00202 {
00203 typename result_type;
00204
00205 static result_type F::apply(T, U);
00206 };
00207 #else
00208
00209
00210 template <typename T, typename U>
00211 struct BinaryFunctor
00212 {
00214 typedef associated_type result_type;
00215
00217 result_type operator()(T, U);
00218 };
00219
00221
00225 template <typename T, typename U>
00226 struct BinaryStaticFunctor
00227 : public BinaryFunctor <T, U>
00228 {
00230 typedef associated_type result_type;
00231
00233 static result_type apply(T, U);
00234
00236 result_type operator()(T, U);
00237 };
00238 #endif
00239
00241
00242 }
00243
00244 #endif // MTL_STD_CONCEPT_INCLUDE