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.
 
 
 
 

71 lignes
2.1 KiB

  1. /*!
  2. * \file utl/meta/detect.h
  3. * \brief Template meta-programming void 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_detect_h__
  21. #define __utl_meta_detect_h__
  22. #include <utl/impl/impl.h>
  23. #include <utl/meta/sfinae.h>
  24. /*!
  25. * \ingroup meta
  26. * \defgroup detect
  27. * Implementation of the detection idiom
  28. */
  29. //! @{
  30. namespace utl {
  31. //! detection idiom (negative case).
  32. template <typename _Def,
  33. typename _AlwaysVoid,
  34. template<typename...> class _Op,
  35. typename... _Args>
  36. struct detector_ {
  37. using value_ = false_;
  38. using type = _Def;
  39. };
  40. //! detection idiom (positive case).
  41. template <typename _Def,
  42. template<typename...> class _Op,
  43. typename... _Args>
  44. struct detector_ <_Def, void_t<_Op<_Args...>>, _Op, _Args...> {
  45. using value_ = true_;
  46. using type = _Op<_Args...>;
  47. };
  48. // Detect whether _Op<_Args...> is a valid type, use _Def if not.
  49. template <typename _Def,
  50. template<typename...> class _Op,
  51. typename... _Args>
  52. using detected_or_ = detector_ <_Def, void, _Op, _Args...>;
  53. // template alias
  54. template <typename _Def,
  55. template<typename...> class _Op,
  56. typename... _Args>
  57. using detected_or_t = typename detected_or_<_Def, _Op, _Args...>::type;
  58. }
  59. //! @}
  60. #endif /* __utl_meta_detect_h__ */