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.
 
 
 
 

63 lignes
1.9 KiB

  1. /*!
  2. * \file useif.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_useif_h__
  21. #define __utl_meta_useif_h__
  22. #include <utl/core/impl.h>
  23. #include <utl/meta/operations.h>
  24. #include <utl/meta/sfinae.h>
  25. /*!
  26. * \ingroup meta
  27. * \defgroup sfinae
  28. * conditional use support header. This is a SFINAE wrapper
  29. */
  30. //! @{
  31. namespace utl {
  32. namespace meta {
  33. //! If same type resolves to _Ret, else SFINAE
  34. template <typename _T1, typename _T2, typename _Ret =_T1>
  35. using use_if_same_t = enable_if_t<
  36. same_<_T1, _T2>::value, _Ret
  37. >;
  38. //! If not same type resolves to _Ret, else SFINAE
  39. template <typename _T1, typename _T2, typename _Ret =_T1>
  40. using use_if_not_same_t = enable_if_t<
  41. !same_<_T1, _T2>::value, _Ret
  42. >;
  43. //! If any type (_T1 or _T2) type resolves to _Ret, else to SFINAE
  44. template <typename T1, typename... Ts>
  45. using use_if_any_t = enable_if_t<
  46. or_<T1, Ts...>::value, T1
  47. >;
  48. //! If both type (_T1 and _T2) type resolves to _Ret, else to SFINAE
  49. template <typename T1, typename... Ts>
  50. using use_if_all_t = enable_if_t<
  51. and_<T1, Ts...>::value, T1
  52. >;
  53. }}
  54. //! @}
  55. #endif /* __utl_meta_useif_h__ */