Micro template library A library for building device drivers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

71 lines
2.1 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/logical.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 = eval<
  36. enable_if<
  37. same_<_T1, _T2>::value, _Ret
  38. >
  39. >;
  40. //! If not same type resolves to _Ret, else SFINAE
  41. template <typename _T1, typename _T2, typename _Ret =_T1>
  42. using use_if_not_same_t = eval<
  43. enable_if<
  44. !same_<_T1, _T2>::value, _Ret
  45. >
  46. >;
  47. //! If any type (_T1 or _T2) type resolves to _Ret, else to SFINAE
  48. template <typename _T1, typename _T2, typename _Ret =_T1>
  49. using use_if_any_t = eval<
  50. enable_if<
  51. or_<_T1, _T2>::value, _Ret
  52. >
  53. >;
  54. //! If both type (_T1 and _T2) type resolves to _Ret, else to SFINAE
  55. template <typename _T1, typename _T2, typename _Ret =_T1>
  56. using use_if_both_t = eval<
  57. enable_if<
  58. and_<_T1, _T2>::value, _Ret
  59. >
  60. >;
  61. }}
  62. //! @}
  63. #endif /* __utl_meta_useif_h__ */