• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef BOOST_HISTOGRAM_DETAIL_NONMEMBER_CONTAINER_ACCESS_HPP
8 #define BOOST_HISTOGRAM_DETAIL_NONMEMBER_CONTAINER_ACCESS_HPP
9 
10 #if __cpp_lib_nonmember_container_access >= 201411
11 
12 #include <iterator>
13 
14 namespace boost {
15 namespace histogram {
16 namespace detail {
17 
18 using std::data;
19 using std::size;
20 
21 } // namespace detail
22 } // namespace histogram
23 } // namespace boost
24 
25 #else // std implementations are not available
26 
27 #include <initializer_list>
28 #include <type_traits>
29 
30 namespace boost {
31 namespace histogram {
32 namespace detail {
33 
34 template <class C>
data(C & c)35 constexpr auto data(C& c) -> decltype(c.data()) {
36   return c.data();
37 }
38 
39 template <class C>
data(const C & c)40 constexpr auto data(const C& c) -> decltype(c.data()) {
41   return c.data();
42 }
43 
44 template <class T, std::size_t N>
data(T (& array)[N])45 constexpr T* data(T (&array)[N]) noexcept {
46   return array;
47 }
48 
49 template <class E>
data(std::initializer_list<E> il)50 constexpr const E* data(std::initializer_list<E> il) noexcept {
51   return il.begin();
52 }
53 
54 template <class C>
size(const C & c)55 constexpr auto size(const C& c) -> decltype(c.size()) {
56   return c.size();
57 }
58 
59 template <class T, std::size_t N>
size(const T (&)[N])60 constexpr std::size_t size(const T (&)[N]) noexcept {
61   return N;
62 }
63 
64 } // namespace detail
65 } // namespace histogram
66 } // namespace boost
67 
68 #endif
69 
70 #endif // BOOST_HISTOGRAM_DETAIL_NONMEMBER_CONTAINER_ACCESS_HPP
71