Micro template library A library for building device drivers
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

61 lines
1.9 KiB

  1. /*!
  2. * \file useif.h
  3. * \brief Template meta-programming SFINAE helpers
  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. */
  19. #ifndef __utl_meta_useif_h__
  20. #define __utl_meta_useif_h__
  21. #include <utl/core/impl.h>
  22. #include <utl/meta/operations.h>
  23. #include <utl/meta/sfinae.h>
  24. /*!
  25. * \ingroup meta
  26. * \addtogroup sfinae
  27. */
  28. //! @{
  29. namespace utl {
  30. namespace meta {
  31. //! If same type resolves to Ret, else SFINAE
  32. template <typename T1, typename T2, typename Ret =T1>
  33. using use_if_same_t = enable_if_t<
  34. eval_v<same_<T1, T2>>, Ret
  35. >;
  36. //! If not same type resolves to Ret, else SFINAE
  37. template <typename T1, typename T2, typename Ret =T1>
  38. using use_if_not_same_t = enable_if_t<
  39. eval_v<not_same_<T1, T2>>, Ret
  40. >;
  41. //! If any type (T1 or T2) type resolves to Ret, else to SFINAE
  42. template <typename T1, typename... Ts>
  43. using use_if_any_t = enable_if_t<
  44. eval_v<or_<T1, Ts...>>, T1
  45. >;
  46. //! If both type (T1 and T2) type resolves to Ret, else to SFINAE
  47. template <typename T1, typename... Ts>
  48. using use_if_all_t = enable_if_t<
  49. eval_v<and_<T1, Ts...>>, T1
  50. >;
  51. }}
  52. //! @}
  53. #endif /* __utl_meta_useif_h__ */