1 //----------------------------------------------------------------------------
2 /// @file traits.hpp
3 /// @brief this file contains the metaprogramming classes  compare_iter and
4 ///         enable_if_not_integral
5 /// @author Copyright(c) 2016 Francisco Jose Tapia (fjtapia@gmail.com )\n
6 ///         Distributed under the Boost Software License, Version 1.0.\n
7 ///         ( See accompanying file LICENSE_1_0.txt or copy at
8 ///           http://www.boost.org/LICENSE_1_0.txt  )
9 /// @version 0.1
10 ///
11 //-----------------------------------------------------------------------------
12 #ifndef __BOOST_SORT_COMMON_UTIL_TRAITS_HPP
13 #define __BOOST_SORT_COMMON_UTIL_TRAITS_HPP
14 
15 #include <functional>
16 #include <iterator>
17 #include <type_traits>
18 
19 namespace boost
20 {
21 namespace sort
22 {
23 namespace common
24 {
25 namespace util
26 {
27 //----------------------------------------------------------------------------
28 //                  USING SENTENCES
29 //----------------------------------------------------------------------------
30 using std::iterator_traits;
31 
32 //
33 //---------------------------------------------------------------------------
34 /// @class value_iter
35 /// @brief From the iterator, obtain the type pointed by it
36 /// @remarks The main utility of this, is simplify the default template
37 ///          parameter of comparison
38 //---------------------------------------------------------------------------
39 template<class iter_t>
40 using value_iter = typename iterator_traits< iter_t >::value_type;
41 //
42 //---------------------------------------------------------------------------
43 /// @class compare_iter
44 /// @brief From the iterator, received as template parameter, obtain the type
45 ///        of the object pointed by the iterator, and with this define the
46 ///        std::less with this type obtained
47 /// @remarks The main utility of this, is simplify the default template
48 ///          parameter of comparison
49 //---------------------------------------------------------------------------
50 template<class iter_t>
51 using compare_iter =  std::less< value_iter< iter_t > >;
52 
53 //
54 //---------------------------------------------------------------------------
55 /// @class enable_if_not_integral
56 /// @brief This is a SFINAE class for to detect if the third parameter in the
57 ///        invocation of the parallel sorting algorithms is an integer
58 ///        representing the number of threads to use or is a comparison object
59 /// @remarks
60 //---------------------------------------------------------------------------
61 template<class T>
62 using enable_if_not_integral =
63       typename std::enable_if< !std::is_integral< T >::value >::type;
64 //
65 //---------------------------------------------------------------------------
66 /// @class enable_if_integral
67 /// @brief This is a SFINAE class for to detect if the third parameter in the
68 ///        invocation of the parallel sorting algorithms is an integer
69 ///        representing the number of threads to use or is a comparison object
70 /// @remarks
71 //---------------------------------------------------------------------------
72 template<class T>
73 using enable_if_integral =
74       typename std::enable_if< std::is_integral< T >::value >::type;
75 
76 //
77 //---------------------------------------------------------------------------
78 /// @class enable_if_string
79 /// @brief This is a SFINAE class for to detect if the parameter is a
80 ///        std::string for to apply specialized parameters in the invocation
81 ///        of the block_indirect_sort algorithm
82 /// @remarks
83 //---------------------------------------------------------------------------
84 template<class T>
85 using enable_if_string =
86       typename std::enable_if< std::is_same< T, std::string >::value >::type;
87 
88 //
89 //---------------------------------------------------------------------------
90 /// @class enable_if_not_string
91 /// @brief This is a SFINAE class for to detect if the parameter is a
92 ///        std::string for to apply specialized parameters in the invocation
93 ///        of the block_indirect_sort algorithm
94 /// @remarks
95 //---------------------------------------------------------------------------
96 template<class T>
97 using enable_if_not_string =
98       typename std::enable_if<! std::is_same< T, std::string >::value >::type;
99 
100 //
101 //---------------------------------------------------------------------------
102 /// @class constructor
103 /// @brief create a functor with the constructor of a class for to be invoked
104 ///        from a bind or a lambda
105 /// @remarks
106 //---------------------------------------------------------------------------
107 template<class T>
108 struct constructor
109 {
110     template<class ... Args>
operator ()boost::sort::common::util::constructor111     void operator()(Args && ... args)
112     {
113         T(std::forward<Args> (args) ...);
114     };
115 };
116 //
117 //****************************************************************************
118 };// End namespace util
119 };// End namespace common
120 };// End namespace sort
121 };// End namespace boost
122 //****************************************************************************
123 #endif
124