<commit_before>/* mbed Microcontroller Library
 * Copyright (c) 2018-2018 ARM Limited
 *
 * 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.
 */

#ifndef MBED_PLATFORM_SPAN_H_
#define MBED_PLATFORM_SPAN_H_

#include <algorithm>
#include <stddef.h>
#include <stdint.h>

#include "platform/mbed_assert.h"

namespace mbed {

/**
 * Special value for the Extent parameter of Span.
 * If the type use this value then the size of the array is stored in the object
 * at runtime.
 */
#define SPAN_DYNAMIC_EXTENT -1

/**
 * View to an array.
 *
 * Spans encapsulate the pointer to an array and its size into a single object.
 * However, it does not manage the lifetime of the array viewed. You can use
 * instances of Span to replace the traditional pair of pointer and size
 * arguments in function calls.
 *
 * You can use the size member function to query the number of elements present
 * in the array, and the subscript operator allow code using this object to
 * access the content of the array viewed.
 *
 * Subspans can be created with the help of the functions first(), last() and
 * subspan().
 *
 * @note You can create Span instances with the help of the function template
 * make_Span() and make_const_Span().
 *
 * @note Span<T, Extent> objects can be implicitly converted to Span<T> objects
 * where required.
 *
 * @tparam ElementType type of objects held in the array viewed.
 *
 * @tparam Extent The size of the array viewed. The default value
 * SPAN_DYNAMIC_SIZE  is special as it allows construction of Span objects of
 * any size (set at runtime).
 */
template<typename ElementType, ptrdiff_t Extent = SPAN_DYNAMIC_EXTENT>
struct Span {

    /**
     * Type of the element contained
     */
    typedef ElementType element_type;

    /**
     * Type of the index.
     */
    typedef ptrdiff_t index_type;

    /**
     * Pointer to an ElementType
     */
    typedef element_type *pointer;

    /**
     * Reference to an ElementType
     */
    typedef element_type &reference;

    /**
     * Size of the Extent; -1 if dynamic.
     */
    static const index_type extent = Extent;

    MBED_STATIC_ASSERT(Extent >= 0, "Invalid extent for a Span");

    /**
     * Construct an empty span.
     *
     * @post a call to size() will return 0, and data() will return NULL.
     *
     * @note This function is not accessible if Extent != SPAN_DYNAMIC_EXTENT or
     * Extent != 0 .
     */
    Span() : _data(NULL) {
        MBED_STATIC_ASSERT(Extent == 0, "Invalid extent for a Span");
    }

    /**
     * Construct a Span from a pointer to a buffer and its size.
     *
     * @param ptr Pointer to the beginning of the data viewed.
     *
     * @param count Number of elements viewed.
     *
     * @pre [ptr, ptr + count) must be be a valid range.
     * @pre count must be equal to extent.<commit_msg>Span: Fix static assert message in default constructor.<commit_after>/* mbed Microcontroller Library
 * Copyright (c) 2018-2018 ARM Limited
 *
 * 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.
 */

#ifndef MBED_PLATFORM_SPAN_H_
#define MBED_PLATFORM_SPAN_H_

#include <algorithm>
#include <stddef.h>
#include <stdint.h>

#include "platform/mbed_assert.h"

namespace mbed {

/**
 * Special value for the Extent parameter of Span.
 * If the type use this value then the size of the array is stored in the object
 * at runtime.
 */
#define SPAN_DYNAMIC_EXTENT -1

/**
 * View to an array.
 *
 * Spans encapsulate the pointer to an array and its size into a single object.
 * However, it does not manage the lifetime of the array viewed. You can use
 * instances of Span to replace the traditional pair of pointer and size
 * arguments in function calls.
 *
 * You can use the size member function to query the number of elements present
 * in the array, and the subscript operator allow code using this object to
 * access the content of the array viewed.
 *
 * Subspans can be created with the help of the functions first(), last() and
 * subspan().
 *
 * @note You can create Span instances with the help of the function template
 * make_Span() and make_const_Span().
 *
 * @note Span<T, Extent> objects can be implicitly converted to Span<T> objects
 * where required.
 *
 * @tparam ElementType type of objects held in the array viewed.
 *
 * @tparam Extent The size of the array viewed. The default value
 * SPAN_DYNAMIC_SIZE  is special as it allows construction of Span objects of
 * any size (set at runtime).
 */
template<typename ElementType, ptrdiff_t Extent = SPAN_DYNAMIC_EXTENT>
struct Span {

    /**
     * Type of the element contained
     */
    typedef ElementType element_type;

    /**
     * Type of the index.
     */
    typedef ptrdiff_t index_type;

    /**
     * Pointer to an ElementType
     */
    typedef element_type *pointer;

    /**
     * Reference to an ElementType
     */
    typedef element_type &reference;

    /**
     * Size of the Extent; -1 if dynamic.
     */
    static const index_type extent = Extent;

    MBED_STATIC_ASSERT(Extent >= 0, "Invalid extent for a Span");

    /**
     * Construct an empty span.
     *
     * @post a call to size() will return 0, and data() will return NULL.
     *
     * @note This function is not accessible if Extent != SPAN_DYNAMIC_EXTENT or
     * Extent != 0 .
     */
    Span() : _data(NULL) {
        MBED_STATIC_ASSERT(
            Extent == 0,
            "Cannot default construct a static-extent Span (unless Extent is 0)"
        );
    }

    /**
     * Construct a Span from a pointer to a buffer and its size.
     *
     * @param ptr Pointer to the beginning of the data viewed.
     *
     * @param count Number of elements viewed.
     *
     * @pre [ptr, ptr + count) must be be a valid range.
     * @pre count must be equal to extent.
{'fraction_non_alphanumeric': 0.078150391490619, 'fraction_numerical': 0.00546609543507165, 'mean_word_length': 2.92463768115942, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5167720', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1898, 'n_words': 875}