traits.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <ciso646>
  15. #include <functional>
  16. #include <iterator>
  17. #include <type_traits>
  18. namespace boost
  19. {
  20. namespace sort
  21. {
  22. namespace common
  23. {
  24. namespace util
  25. {
  26. //----------------------------------------------------------------------------
  27. // USING SENTENCES
  28. //----------------------------------------------------------------------------
  29. using std::iterator_traits;
  30. //
  31. //---------------------------------------------------------------------------
  32. /// @class value_iter
  33. /// @brief From the iterator, obtain the type pointed by it
  34. /// @remarks The main utility of this, is simplify the default template
  35. /// parameter of comparison
  36. //---------------------------------------------------------------------------
  37. template<class iter_t>
  38. using value_iter = typename iterator_traits< iter_t >::value_type;
  39. //
  40. //---------------------------------------------------------------------------
  41. /// @class compare_iter
  42. /// @brief From the iterator, received as template parameter, obtain the type
  43. /// of the object pointed by the iterator, and with this define the
  44. /// std::less with this type obtained
  45. /// @remarks The main utility of this, is simplify the default template
  46. /// parameter of comparison
  47. //---------------------------------------------------------------------------
  48. template<class iter_t>
  49. using compare_iter = std::less< value_iter< iter_t > >;
  50. //
  51. //---------------------------------------------------------------------------
  52. /// @class enable_if_not_integral
  53. /// @brief This is a SFINAE class for to detect if the third parameter in the
  54. /// invocation of the parallel sorting algorithms is an integer
  55. /// representing the number of threads to use or is a comparison object
  56. /// @remarks
  57. //---------------------------------------------------------------------------
  58. template<class T>
  59. using enable_if_not_integral =
  60. typename std::enable_if< !std::is_integral< T >::value >::type;
  61. //
  62. //---------------------------------------------------------------------------
  63. /// @class enable_if_integral
  64. /// @brief This is a SFINAE class for to detect if the third parameter in the
  65. /// invocation of the parallel sorting algorithms is an integer
  66. /// representing the number of threads to use or is a comparison object
  67. /// @remarks
  68. //---------------------------------------------------------------------------
  69. template<class T>
  70. using enable_if_integral =
  71. typename std::enable_if< std::is_integral< T >::value >::type;
  72. //
  73. //---------------------------------------------------------------------------
  74. /// @class enable_if_string
  75. /// @brief This is a SFINAE class for to detect if the parameter is a
  76. /// std::string for to apply specialized parameters in the invocation
  77. /// of the block_indirect_sort algorithm
  78. /// @remarks
  79. //---------------------------------------------------------------------------
  80. template<class T>
  81. using enable_if_string =
  82. typename std::enable_if< std::is_same< T, std::string >::value >::type;
  83. //
  84. //---------------------------------------------------------------------------
  85. /// @class enable_if_not_string
  86. /// @brief This is a SFINAE class for to detect if the parameter is a
  87. /// std::string for to apply specialized parameters in the invocation
  88. /// of the block_indirect_sort algorithm
  89. /// @remarks
  90. //---------------------------------------------------------------------------
  91. template<class T>
  92. using enable_if_not_string =
  93. typename std::enable_if<! std::is_same< T, std::string >::value >::type;
  94. //
  95. //---------------------------------------------------------------------------
  96. /// @class constructor
  97. /// @brief create a functor with the constructor of a class for to be invoked
  98. /// from a bind or a lambda
  99. /// @remarks
  100. //---------------------------------------------------------------------------
  101. template<class T>
  102. struct constructor
  103. {
  104. template<class ... Args>
  105. void operator()(Args && ... args)
  106. {
  107. T(std::forward<Args> (args) ...);
  108. }
  109. };
  110. //
  111. //****************************************************************************
  112. };// End namespace util
  113. };// End namespace common
  114. };// End namespace sort
  115. };// End namespace boost
  116. //****************************************************************************
  117. #endif