Commit d7d48e47 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

c_array

Summary: [Folly] `c_array`, a container for returning C arrays from `constexpr` functions. May be used until C++17 may be assumed, since C++17 specifies `constexpr` member functions of `std::array` which make `std::array` suitable for the purpose and a better choice since it  can house zero-sized arrays.

Reviewed By: markisaa

Differential Revision: D21382680

fbshipit-source-id: 56a6528bb05988c1f1c8916f9267575783dc6276
parent c518e9ec
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
namespace folly {
// c_array
//
// A container for C arrays. Suitable for returning non-zero-sized C arrays
// from constexpr functions.
//
// Prefer std::array when using C++17 or later.
template <typename V, size_t N>
struct c_array {
V data[N];
};
} // namespace folly
......@@ -20,15 +20,14 @@
#include <type_traits>
#include <folly/Portability.h>
#include <folly/lang/CArray.h>
namespace folly {
namespace detail {
template <std::size_t S>
struct pretty_carray {
char data[S];
};
using pretty_carray = c_array<char, S>;
template <std::size_t S>
static constexpr pretty_carray<S> pretty_carray_from(char const (&in)[S]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment