MCPcopy Create free account
hub / github.com/Neargye/magic_enum / array

Class array

include/magic_enum/magic_enum_containers.hpp:335–448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
334template <typename E, typename V, typename Index = default_indexing<E>>
335struct array {
336 static_assert(std::is_enum_v<E>);
337 static_assert(std::is_trivially_constructible_v<Index>);
338 static_assert(enum_count<E>() > 0 && Index::at(enum_values<E>().front()));
339
340 using index_type = Index;
341 using container_type = std::array<V, enum_count<E>()>;
342
343 using value_type = typename container_type::value_type;
344 using size_type = typename container_type::size_type;
345 using difference_type = typename container_type::difference_type;
346 using reference = typename container_type::reference;
347 using const_reference = typename container_type::const_reference;
348 using pointer = typename container_type::pointer;
349 using const_pointer = typename container_type::const_pointer;
350 using iterator = typename container_type::iterator;
351 using const_iterator = typename container_type::const_iterator;
352 using reverse_iterator = typename container_type::reverse_iterator;
353 using const_reverse_iterator = typename container_type::const_reverse_iterator;
354
355 constexpr reference at(E pos) {
356 if (auto index = index_type::at(pos)) {
357 return a[*index];
358 }
359 MAGIC_ENUM_THROW(std::out_of_range("magic_enum::containers::array::at Unrecognized position"));
360 }
361
362 constexpr const_reference at(E pos) const {
363 if (auto index = index_type::at(pos)) {
364 return a[*index];
365 }
366 MAGIC_ENUM_THROW(std::out_of_range("magic_enum::containers::array::at: Unrecognized position"));
367 }
368
369 [[nodiscard]] constexpr reference operator[](E pos) {
370 auto i = index_type::at(pos);
371 return MAGIC_ENUM_ASSERT(i), a[*i];
372 }
373
374 [[nodiscard]] constexpr const_reference operator[](E pos) const {
375 auto i = index_type::at(pos);
376 return MAGIC_ENUM_ASSERT(i), a[*i];
377 }
378
379 [[nodiscard]] constexpr reference front() noexcept { return a.front(); }
380
381 [[nodiscard]] constexpr const_reference front() const noexcept { return a.front(); }
382
383 [[nodiscard]] constexpr reference back() noexcept { return a.back(); }
384
385 [[nodiscard]] constexpr const_reference back() const noexcept { return a.back(); }
386
387 [[nodiscard]] constexpr pointer data() noexcept { return a.data(); }
388
389 [[nodiscard]] constexpr const_pointer data() const noexcept { return a.data(); }
390
391 [[nodiscard]] constexpr iterator begin() noexcept { return a.begin(); }
392

Callers

nothing calls this directly

Calls 1

frontMethod · 0.80

Tested by

no test coverage detected