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.
 
 
 
 

86 lignes
2.4 KiB

  1. /*!
  2. * \file sfinae.h
  3. * \brief Template meta-programming SFINAE helpers
  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_sfinae_h__
  21. #define __utl_meta_sfinae_h__
  22. #include <utl/core/impl.h>
  23. /*!
  24. * \ingroup meta
  25. * \defgroup sfinae
  26. * conditional use support header.
  27. */
  28. //! @{
  29. namespace utl {
  30. namespace meta {
  31. //! Tool to enable a partial specialization only if a boolean condition is true.
  32. //! @{
  33. namespace detail {
  34. template <typename... T>
  35. struct dev_null { using type = dev_null; }; //< Same as typelist
  36. template <bool If> struct when_ { };
  37. template <> struct when_<true> { using type = void; };
  38. }
  39. //! Well formed only if \p If is true
  40. template <bool If>
  41. using when = type_<detail::when_<If>>;
  42. //! Well formed only if all of \p Ifs are \c true
  43. template <bool ...Ifs>
  44. using when_all = detail::dev_null<
  45. when<Ifs>...
  46. >;
  47. //! @}
  48. //! select _Tp if \p If is true, else SFINAE
  49. //! We implement eneble_if so we don't have to pull entire \c <type_traits> from stl
  50. //! @{
  51. template <bool If, typename _Tp = void>
  52. struct enable_if {
  53. using type = _Tp;
  54. };
  55. template<typename _Tp>
  56. struct enable_if <false, _Tp> { /* SFINAE*/ };
  57. //! Alias template for enable_if
  58. template <bool If, typename _Tp = void>
  59. using use_if = enable_if<If, _Tp>;
  60. //! Publicly recognized alias template for enable_if
  61. template<bool If, typename _Tp = void>
  62. using enable_if_t = type_<
  63. enable_if<If, _Tp>
  64. >;
  65. //! Uniform alias template for use_if
  66. template<bool If, typename _Tp = void>
  67. using use_if_t = type_<
  68. enable_if<If, _Tp>
  69. >;
  70. //! @}
  71. }}
  72. //! @}
  73. #endif /* __utl_meta_sfinae_h__ */