first_scalar.hpp 813 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright 2019 Glen Joseph Fernandes
  3. ([email protected])
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_CORE_FIRST_SCALAR_HPP
  8. #define BOOST_CORE_FIRST_SCALAR_HPP
  9. #include <boost/config.hpp>
  10. #include <cstddef>
  11. namespace boost {
  12. namespace detail {
  13. template<class T>
  14. struct make_scalar {
  15. typedef T type;
  16. };
  17. template<class T, std::size_t N>
  18. struct make_scalar<T[N]> {
  19. typedef typename make_scalar<T>::type type;
  20. };
  21. } /* detail */
  22. template<class T>
  23. BOOST_CONSTEXPR inline T*
  24. first_scalar(T* p) BOOST_NOEXCEPT
  25. {
  26. return p;
  27. }
  28. template<class T, std::size_t N>
  29. BOOST_CONSTEXPR inline typename detail::make_scalar<T>::type*
  30. first_scalar(T (*p)[N]) BOOST_NOEXCEPT
  31. {
  32. return boost::first_scalar(&(*p)[0]);
  33. }
  34. } /* boost */
  35. #endif