2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <initializer_list>
23 * include or backport:
29 #if __cpp_lib_nonmember_container_access >= 201411 || _MSC_VER
33 /* using override */ using std::size;
34 /* using override */ using std::empty;
35 /* using override */ using std::data;
43 // mimic: std::size, C++17
45 constexpr auto size(C const& c) -> decltype(c.size()) {
48 template <typename T, std::size_t N>
49 constexpr std::size_t size(T const (&)[N]) noexcept {
53 // mimic: std::empty, C++17
55 constexpr auto empty(C const& c) -> decltype(c.empty()) {
58 template <typename T, std::size_t N>
59 constexpr bool empty(T const (&)[N]) noexcept {
60 // while zero-length arrays are not allowed in the language, some compilers
61 // may permit them in some cases
65 constexpr bool empty(std::initializer_list<E> il) noexcept {
66 return il.size() == 0;
69 // mimic: std::data, C++17
71 constexpr auto data(C& c) -> decltype(c.data()) {
75 constexpr auto data(C const& c) -> decltype(c.data()) {
78 template <typename T, std::size_t N>
79 constexpr T* data(T (&a)[N]) noexcept {
83 constexpr E const* data(std::initializer_list<E> il) noexcept {