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.
 
 
 
 

72 lines
2.0 KiB

  1. /*!
  2. * \file sfinae.h
  3. * \brief Template meta-programming SFINAE helpers
  4. *
  5. * Copyright (C) 2018-2019 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_sfinae_h__
  21. #define __utl_meta_sfinae_h__
  22. #include <utl/core/impl.h>
  23. #include <type_traits>
  24. /*!
  25. * \ingroup meta
  26. * \defgroup sfinae
  27. * conditional use support header.
  28. */
  29. //! @{
  30. namespace utl {
  31. namespace meta {
  32. //! Tool to enable a partial specialization only if a boolean condition is true.
  33. //! @{
  34. namespace detail {
  35. // template <typename... T>
  36. // struct dev_null { using type = dev_null; }; //< Same as typelist
  37. template <bool If> struct when_ { };
  38. template <> struct when_<true> { using type = void; };
  39. }
  40. //! Well formed only if \p If is true
  41. template <bool If>
  42. using when = eval< detail::when_<If> >;
  43. // //! Well formed only if all of \p Ifs are \c true
  44. // template <bool ...Ifs>
  45. // using when_all = detail::dev_null<
  46. // when<Ifs>...
  47. // >;
  48. //! @}
  49. //! enable_if
  50. //! @{
  51. //! enable_if, imported from stl
  52. template <bool If, typename _Tp = void> using enable_if = std::enable_if<If, _Tp>;
  53. //! alias template for enable_if
  54. template<bool If, typename _Tp = void> using enable_if_t = eval< enable_if<If, _Tp> >;
  55. //! @}
  56. }}
  57. //! @}
  58. #endif /* __utl_meta_sfinae_h__ */