data.hpp 780 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. Copyright 2023 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_DATA_HPP
  8. #define BOOST_CORE_DATA_HPP
  9. #include <initializer_list>
  10. #include <cstddef>
  11. namespace boost {
  12. template<class C>
  13. inline constexpr auto
  14. data(C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
  15. {
  16. return c.data();
  17. }
  18. template<class C>
  19. inline constexpr auto
  20. data(const C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
  21. {
  22. return c.data();
  23. }
  24. template<class T, std::size_t N>
  25. inline constexpr T*
  26. data(T(&a)[N]) noexcept
  27. {
  28. return a;
  29. }
  30. template<class T>
  31. inline constexpr const T*
  32. data(std::initializer_list<T> l) noexcept
  33. {
  34. return l.begin();
  35. }
  36. } /* boost */
  37. #endif