data.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright 2023 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  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 <iterator>
  10. // Note: MSVC doesn't define __cpp_lib_nonmember_container_access but supports the feature even in C++14 mode
  11. #if (defined(__cpp_lib_nonmember_container_access) && (__cpp_lib_nonmember_container_access >= 201411l)) || \
  12. (defined(_MSC_VER) && (_MSC_VER >= 1900))
  13. namespace boost {
  14. using std::data;
  15. } /* boost */
  16. #else // (defined(__cpp_lib_nonmember_container_access) ...
  17. #include <cstddef>
  18. #include <initializer_list>
  19. namespace boost {
  20. template<class C>
  21. inline constexpr auto
  22. data(C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
  23. {
  24. return c.data();
  25. }
  26. template<class C>
  27. inline constexpr auto
  28. data(const C& c) noexcept(noexcept(c.data())) -> decltype(c.data())
  29. {
  30. return c.data();
  31. }
  32. template<class T, std::size_t N>
  33. inline constexpr T*
  34. data(T(&a)[N]) noexcept
  35. {
  36. return a;
  37. }
  38. template<class T>
  39. inline constexpr const T*
  40. data(std::initializer_list<T> l) noexcept
  41. {
  42. return l.begin();
  43. }
  44. } /* boost */
  45. #endif // (defined(__cpp_lib_nonmember_container_access) ...
  46. #endif