зеркало из https://github.com/microsoft/STL.git
73 строки
1.9 KiB
C++
73 строки
1.9 KiB
C++
// initializer_list standard header (core)
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#pragma once
|
|
#ifndef _INITIALIZER_LIST_
|
|
#define _INITIALIZER_LIST_
|
|
#include <yvals_core.h>
|
|
#if _STL_COMPILER_PREPROCESSOR
|
|
#include <cstddef>
|
|
|
|
#pragma pack(push, _CRT_PACKING)
|
|
#pragma warning(push, _STL_WARNING_LEVEL)
|
|
#pragma warning(disable : _STL_DISABLED_WARNINGS)
|
|
_STL_DISABLE_CLANG_WARNINGS
|
|
#pragma push_macro("new")
|
|
#undef new
|
|
|
|
_STD_BEGIN
|
|
// CLASS TEMPLATE initializer_list
|
|
template <class _Elem>
|
|
class initializer_list {
|
|
public:
|
|
using value_type = _Elem;
|
|
using reference = const _Elem&;
|
|
using const_reference = const _Elem&;
|
|
using size_type = size_t;
|
|
|
|
using iterator = const _Elem*;
|
|
using const_iterator = const _Elem*;
|
|
|
|
constexpr initializer_list() noexcept : _First(nullptr), _Last(nullptr) {}
|
|
|
|
constexpr initializer_list(const _Elem* _First_arg, const _Elem* _Last_arg) noexcept
|
|
: _First(_First_arg), _Last(_Last_arg) {}
|
|
|
|
_NODISCARD constexpr const _Elem* begin() const noexcept {
|
|
return _First;
|
|
}
|
|
|
|
_NODISCARD constexpr const _Elem* end() const noexcept {
|
|
return _Last;
|
|
}
|
|
|
|
_NODISCARD constexpr size_t size() const noexcept {
|
|
return static_cast<size_t>(_Last - _First);
|
|
}
|
|
|
|
private:
|
|
const _Elem* _First;
|
|
const _Elem* _Last;
|
|
};
|
|
|
|
// FUNCTION TEMPLATE begin
|
|
template <class _Elem>
|
|
_NODISCARD constexpr const _Elem* begin(initializer_list<_Elem> _Ilist) noexcept {
|
|
return _Ilist.begin();
|
|
}
|
|
|
|
// FUNCTION TEMPLATE end
|
|
template <class _Elem>
|
|
_NODISCARD constexpr const _Elem* end(initializer_list<_Elem> _Ilist) noexcept {
|
|
return _Ilist.end();
|
|
}
|
|
_STD_END
|
|
#pragma pop_macro("new")
|
|
_STL_RESTORE_CLANG_WARNINGS
|
|
#pragma warning(pop)
|
|
#pragma pack(pop)
|
|
#endif // _STL_COMPILER_PREPROCESSOR
|
|
#endif // _INITIALIZER_LIST_
|