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.
 
 
 
 

65 lignes
2.0 KiB

  1. /*!
  2. * \file use.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_use_h__
  21. #define __utl_meta_use_h__
  22. #include <utl/impl/version.h>
  23. #include <utl/meta/logical.h>
  24. /*!
  25. * \ingroup meta
  26. * \defgroup use
  27. * conditional use support header. This is a SFINAE helper
  28. */
  29. //! @{
  30. namespace utl {
  31. //! If same type resolves to _Ret, else to SFINAE
  32. //! @{
  33. template <typename _Tp1, typename _Tp2, typename _Ret>
  34. struct use_if_same_ {
  35. using type = enable_if_t <
  36. same_<_Tp1, _Tp2>::value,
  37. _Ret
  38. >;
  39. };
  40. template <typename _Tp1, typename _Tp2, typename _Ret>
  41. using use_if_same_t = typename use_if_same_<_Tp1, _Tp2, _Ret>::type;
  42. //! @}
  43. //! If same type resolves to SFINAE, else to _Ret
  44. //! @{
  45. template <typename _Tp1, typename _Tp2, typename _Ret>
  46. struct discard_if_same_ {
  47. using type = enable_if_t <
  48. !same_<_Tp1, _Tp2>::value,
  49. _Ret
  50. >;
  51. };
  52. template <typename _Tp1, typename _Tp2, typename _Ret>
  53. using discard_if_same_t = typename discard_if_same_<_Tp1, _Tp2, _Ret>::type;
  54. //! @}
  55. }
  56. //! @}
  57. #endif /* __utl_meta_use_h__ */