Micro template library A library for building device drivers
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

93 lignes
2.4 KiB

  1. /*!
  2. * \file selection.h
  3. * \brief Template meta-programming type selections.
  4. *
  5. * Copyright (C) 2018 Christos Choutouridis
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation, either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef __utl_meta_selection_h__
  21. #define __utl_meta_selection_h__
  22. #include <utl/core/impl.h>
  23. #include <utl/meta/integral.h>
  24. #include <utl/meta/sfinae.h>
  25. /*!
  26. * \ingroup meta
  27. * \defgroup type selection
  28. * Type selection support header
  29. */
  30. //! @{
  31. namespace utl {
  32. namespace meta{
  33. /*!
  34. * Type selection
  35. */
  36. //! @{
  37. //! if_, if_c
  38. //! @{
  39. namespace detail {
  40. template <bool If, typename...>
  41. struct if_c_ {
  42. using type = nil_; //!< avoid ill formed result
  43. };
  44. template<typename Then>
  45. struct if_c_<true, Then> {
  46. using type = Then;
  47. };
  48. template<typename Then, typename Else>
  49. struct if_c_<true, Then, Else> {
  50. using type = Then;
  51. };
  52. template<typename Then, typename Else>
  53. struct if_c_<false, Then, Else> {
  54. using type = Else;
  55. };
  56. }
  57. //! Select one type or another depending on a compile-time Boolean.
  58. template <bool B, typename... Args>
  59. using if_c = type_<detail::if_c_<B, Args...>>;
  60. //! Select one type or another depending on a compile-time Boolean type
  61. template <typename If, typename... Args>
  62. using if_ = if_c<If::type::value, Args...>;
  63. //! @}
  64. /*!
  65. * Named type selectors
  66. */
  67. //! @{
  68. //! Select the first type of a type sequence
  69. template <typename T1, typename ...>
  70. struct first_of {
  71. using type = T1;
  72. };
  73. //! Select the second type of a type sequence
  74. template <typename T1, typename T2, typename ...>
  75. struct second_of {
  76. using type = T2;
  77. };
  78. //! @}
  79. }}
  80. //! @}
  81. #endif /* __utl_meta_selection_h__ */