if_default.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * https://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * Copyright (c) 2025 Andrey Semashev
  7. */
  8. #ifndef BOOST_ITERATOR_DETAIL_IF_DEFAULT_HPP_INCLUDED_
  9. #define BOOST_ITERATOR_DETAIL_IF_DEFAULT_HPP_INCLUDED_
  10. #include <boost/core/use_default.hpp>
  11. namespace boost {
  12. namespace iterators {
  13. namespace detail {
  14. // If T is use_default, return Default, otherwise - Nondefault.
  15. // By default, Nondefault is T, which means
  16. // the metafunction can be called with just two parameters
  17. // and in that case will return either T or Default.
  18. template< typename T, typename Default, typename Nondefault = T >
  19. struct if_default
  20. {
  21. using type = Nondefault;
  22. };
  23. template< typename Default, typename Nondefault >
  24. struct if_default< use_default, Default, Nondefault >
  25. {
  26. using type = Default;
  27. };
  28. template< typename T, typename Default, typename Nondefault = T >
  29. using if_default_t = typename if_default< T, Default, Nondefault >::type;
  30. } // namespace detail
  31. } // namespace iterators
  32. } // namespace boost
  33. #endif // BOOST_ITERATOR_DETAIL_IF_DEFAULT_HPP_INCLUDED_