traits.hpp 4.8 KB

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