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.
 
 
 
 

80 lignes
2.4 KiB

  1. /*!
  2. * \file selection.h
  3. * \brief Template meta-programming type selections.
  4. *
  5. * \copyright
  6. * Copyright (C) 2018 Christos Choutouridis <christos@choutouridis.net>\n
  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.\n
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.\n
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __utl_meta_selection_h__
  19. #define __utl_meta_selection_h__
  20. #include <utl/core/impl.h>
  21. #include <utl/meta/basic.h>
  22. /*!
  23. * \ingroup meta
  24. * \defgroup selection Selection
  25. * Type selection support header
  26. */
  27. //! @{
  28. namespace utl {
  29. namespace meta{
  30. //! \name if implementation
  31. //! @{
  32. namespace details {
  33. template <bool If, typename...>
  34. struct if_c_ {
  35. using type = nil_; //< avoid ill formed result
  36. };
  37. template<typename Then>
  38. struct if_c_<true, Then> {
  39. using type = Then;
  40. };
  41. template<typename Then, typename Else>
  42. struct if_c_<true, Then, Else> {
  43. using type = Then;
  44. };
  45. template<typename Then, typename Else>
  46. struct if_c_<false, Then, Else> {
  47. using type = Else;
  48. };
  49. }
  50. //! Select one type or another depending on a compile-time Boolean.
  51. template <bool B, typename... Args>
  52. using if_c = eval_t<details::if_c_<B, Args...>>;
  53. //! Select one type or another depending on a compile-time Boolean type
  54. template <typename If, typename... Args>
  55. using if_ = if_c<If::type::value, Args...>;
  56. //! @}
  57. /*!
  58. * \name Named type selectors
  59. */
  60. //! @{
  61. //! Select the first type of a type sequence
  62. template <typename T1, typename ...> using first_of = T1;
  63. //! Select the second type of a type sequence
  64. template <typename T1, typename T2, typename ...> using second_of = T2;
  65. //! @}
  66. }}
  67. //! @}
  68. #endif /* __utl_meta_selection_h__ */