Boost.uBlas 1.49
Linear Algebra in C++: matrices, vectors and numeric algorithms

returntype_deduction.hpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2001-2003 Joel de Guzman
00003  *
00004  *  Use, modification and distribution is subject to the Boost Software
00005  *  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00006  *    http://www.boost.org/LICENSE_1_0.txt)
00007  */
00008 #ifndef _BOOST_UBLAS_NUMERICTYPE_DEDUCTION_
00009 #define _BOOST_UBLAS_NUMERICTYPE_DEDUCTION_
00010 
00011 // See original in boost-sandbox/boost/utility/type_deduction.hpp for comments
00012 
00013 #include <boost/mpl/vector/vector20.hpp>
00014 #include <boost/mpl/at.hpp>
00015 #include <boost/mpl/or.hpp>
00016 #include <boost/mpl/identity.hpp>
00017 #include <boost/type_traits/remove_cv.hpp>
00018 #include <boost/type_traits/is_same.hpp>
00019 #include <boost/utility/enable_if.hpp>
00020 
00021 namespace boost { namespace numeric { namespace ublas {
00022 
00023 struct error_cant_deduce_type {};
00024 
00025   namespace type_deduction_detail
00026   {
00027     typedef char(&bool_value_type)[1];
00028     typedef char(&float_value_type)[2];
00029     typedef char(&double_value_type)[3];
00030     typedef char(&long_double_value_type)[4];
00031     typedef char(&char_value_type)[5];
00032     typedef char(&schar_value_type)[6];
00033     typedef char(&uchar_value_type)[7];
00034     typedef char(&short_value_type)[8];
00035     typedef char(&ushort_value_type)[9];
00036     typedef char(&int_value_type)[10];
00037     typedef char(&uint_value_type)[11];
00038     typedef char(&long_value_type)[12];
00039     typedef char(&ulong_value_type)[13];
00040     
00041     typedef char(&x_value_type)[14];
00042     typedef char(&y_value_type)[15];
00043 
00044     typedef char(&cant_deduce_type)[16];
00045 
00046     template <typename T, typename PlainT = typename remove_cv<T>::type>
00047     struct is_basic
00048         : mpl::or_<
00049           typename mpl::or_<
00050               is_same<PlainT, bool>
00051             , is_same<PlainT, float>
00052             , is_same<PlainT, double>
00053             , is_same<PlainT, long double>
00054           > ::type,
00055           typename mpl::or_<
00056               is_same<PlainT, char>
00057             , is_same<PlainT, signed char>
00058             , is_same<PlainT, unsigned char>
00059             , is_same<PlainT, short>
00060             , is_same<PlainT, unsigned short>
00061             > ::type,
00062           typename mpl::or_<
00063               is_same<PlainT, int>
00064             , is_same<PlainT, unsigned int>
00065             , is_same<PlainT, long>
00066             , is_same<PlainT, unsigned long>
00067             > ::type
00068         > {};
00069 
00070     struct asymmetric;
00071 
00072     template <typename X, typename Y>
00073     cant_deduce_type
00074     test(...); // The black hole !!!
00075 
00076     template <typename X, typename Y>
00077     bool_value_type
00078     test(bool const&);
00079 
00080     template <typename X, typename Y>
00081     float_value_type
00082     test(float const&);
00083     
00084     template <typename X, typename Y>
00085     double_value_type
00086     test(double const&);
00087 
00088     template <typename X, typename Y>
00089     long_double_value_type
00090     test(long double const&);
00091 
00092     template <typename X, typename Y>
00093     char_value_type
00094     test(char const&);
00095 
00096     template <typename X, typename Y>
00097     schar_value_type
00098     test(signed char const&);
00099 
00100     template <typename X, typename Y>
00101     uchar_value_type
00102     test(unsigned char const&);
00103 
00104     template <typename X, typename Y>
00105     short_value_type
00106     test(short const&);
00107 
00108     template <typename X, typename Y>
00109     ushort_value_type
00110     test(unsigned short const&);
00111 
00112     template <typename X, typename Y>
00113     int_value_type
00114     test(int const&);
00115 
00116     template <typename X, typename Y>
00117     uint_value_type
00118     test(unsigned int const&);
00119 
00120     template <typename X, typename Y>
00121     long_value_type
00122     test(long const&);
00123 
00124     template <typename X, typename Y>
00125     ulong_value_type
00126     test(unsigned long const&);
00127 
00128     template <typename X, typename Y>
00129     typename disable_if<
00130         is_basic<X>, x_value_type
00131     >::type
00132     test(X const&);
00133 
00134     template <typename X, typename Y>
00135     typename disable_if<
00136         mpl::or_<
00137             is_basic<Y>
00138           , is_same<Y, asymmetric>
00139           , is_same<const X, const Y>
00140         >
00141       , y_value_type
00142     >::type
00143     test(Y const&);
00144 
00145     template <typename X, typename Y>
00146     struct base_result_of
00147     {
00148         typedef typename remove_cv<X>::type x_type;
00149         typedef typename remove_cv<Y>::type y_type;
00150 
00151         typedef mpl::vector16<
00152             mpl::identity<bool>
00153           , mpl::identity<float>
00154           , mpl::identity<double>
00155           , mpl::identity<long double>
00156           , mpl::identity<char>
00157           , mpl::identity<signed char>
00158           , mpl::identity<unsigned char>
00159           , mpl::identity<short>
00160           , mpl::identity<unsigned short>
00161           , mpl::identity<int>
00162           , mpl::identity<unsigned int>
00163           , mpl::identity<long>
00164           , mpl::identity<unsigned long>
00165           , mpl::identity<x_type>
00166           , mpl::identity<y_type>
00167           , mpl::identity<error_cant_deduce_type>
00168         >
00169         types;
00170     };
00171 
00172 }}} } // namespace boost::numeric::ublas ::type_deduction_detail
00173 
00174 #endif