Chris@16
|
1 ////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright Vicente J. Botet Escriba 2010
|
Chris@16
|
4 //
|
Chris@101
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@101
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // See http://www.boost.org/libs/mpl for documentation.
|
Chris@16
|
10 //
|
Chris@16
|
11 ////////////////////////////////////////////////////////////////////
|
Chris@16
|
12 #ifndef BOOST_MPL_SIGN_HPP_INCLUDED
|
Chris@16
|
13 #define BOOST_MPL_SIGN_HPP_INCLUDED
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/mpl/integral_c.hpp>
|
Chris@16
|
16 #include <boost/mpl/aux_/na_spec.hpp>
|
Chris@16
|
17 #include <boost/mpl/aux_/lambda_support.hpp>
|
Chris@16
|
18 #include <boost/mpl/aux_/config/integral.hpp>
|
Chris@16
|
19 #include <boost/mpl/aux_/config/static_constant.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #if !defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2) \
|
Chris@16
|
22 && !defined(BOOST_MPL_PREPROCESSING_MODE) \
|
Chris@101
|
23 && !defined(__CUDACC__) \
|
Chris@16
|
24 && ( defined(BOOST_MSVC) \
|
Chris@16
|
25 || BOOST_WORKAROUND(__EDG_VERSION__, <= 238) \
|
Chris@16
|
26 )
|
Chris@16
|
27
|
Chris@16
|
28 # define BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2
|
Chris@16
|
29
|
Chris@16
|
30 #endif
|
Chris@16
|
31
|
Chris@16
|
32 namespace boost { namespace mpl {
|
Chris@16
|
33
|
Chris@16
|
34 template< typename Tag > struct sign_impl;
|
Chris@16
|
35
|
Chris@16
|
36 template< typename T > struct sign_tag
|
Chris@16
|
37 {
|
Chris@16
|
38 typedef typename T::tag type;
|
Chris@16
|
39 };
|
Chris@16
|
40
|
Chris@16
|
41 template<
|
Chris@16
|
42 typename BOOST_MPL_AUX_NA_PARAM(N)
|
Chris@16
|
43 >
|
Chris@16
|
44 struct sign
|
Chris@16
|
45 : sign_impl<
|
Chris@16
|
46 typename sign_tag<N>::type
|
Chris@16
|
47 >::template apply<N>::type
|
Chris@16
|
48 {
|
Chris@16
|
49 BOOST_MPL_AUX_LAMBDA_SUPPORT(1, sign, (N))
|
Chris@16
|
50 };
|
Chris@16
|
51
|
Chris@16
|
52 BOOST_MPL_AUX_NA_SPEC(1, sign)
|
Chris@16
|
53
|
Chris@16
|
54 template<
|
Chris@16
|
55 typename T
|
Chris@16
|
56 , T n1
|
Chris@16
|
57 >
|
Chris@16
|
58 struct sign_c
|
Chris@16
|
59 : sign<integral_c<T,n1> >
|
Chris@16
|
60 {
|
Chris@16
|
61 };
|
Chris@16
|
62
|
Chris@16
|
63 #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2)
|
Chris@16
|
64 namespace aux {
|
Chris@16
|
65 template< typename T, T n > struct sign_wknd
|
Chris@16
|
66 {
|
Chris@16
|
67 BOOST_STATIC_CONSTANT(T, value = (n == 0 ? 0 : (n < 0 ? -1 : 1)));
|
Chris@16
|
68 typedef integral_c<T,value> type;
|
Chris@16
|
69 };
|
Chris@16
|
70 }
|
Chris@16
|
71 #endif
|
Chris@16
|
72
|
Chris@16
|
73 template<>
|
Chris@16
|
74 struct sign_impl<integral_c_tag>
|
Chris@16
|
75 {
|
Chris@16
|
76 #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2)
|
Chris@16
|
77 template< typename N > struct apply
|
Chris@16
|
78 : aux::sign_wknd< typename N::value_type, N::value >
|
Chris@16
|
79 #else
|
Chris@16
|
80 template< typename N > struct apply
|
Chris@16
|
81 : integral_c< typename N::value_type, (N::value == 0 ? 0 : (N::value < 0 ? -1 : 1)) >
|
Chris@101
|
82 #endif
|
Chris@16
|
83 {
|
Chris@16
|
84 };
|
Chris@16
|
85 };
|
Chris@16
|
86
|
Chris@16
|
87 }}
|
Chris@16
|
88
|
Chris@16
|
89 #endif // BOOST_MPL_SIGN_HPP_INCLUDED
|