SpECTRE Documentation Coverage Report
Current view: top level - Utilities - TupleSlice.hpp Hit Total Coverage
Commit: 817e13c5144619b701c7cd870655d8dbf94ab8ce Lines: 4 4 100.0 %
Date: 2024-07-19 22:17:05
Legend: Lines: hit not hit

          Line data    Source code
       1           1 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : /// \file
       5             : /// Defines functions for slicing tuples
       6             : 
       7             : #pragma once
       8             : 
       9             : #include <cstddef>
      10             : #include <tuple>
      11             : #include <utility>
      12             : 
      13             : namespace tuple_impl_detail {
      14             : template <size_t Start, typename Tuple, size_t... Is>
      15             : constexpr std::tuple<std::tuple_element_t<Is + Start, std::decay_t<Tuple>>...>
      16             : slice_impl(Tuple&& tuple, std::index_sequence<Is...> /*meta*/) {
      17             :   return {std::get<Is + Start>(std::forward<Tuple>(tuple))...};
      18             : }
      19             : }  // namespace tuple_impl_detail
      20             : 
      21             : /// \ingroup UtilitiesGroup
      22             : /// The subset of elements in `tuple` from index `Start` to (excluding) `Stop`
      23             : template <size_t Start, size_t Stop, typename Tuple>
      24           1 : constexpr auto tuple_slice(Tuple&& tuple) {
      25             :   constexpr size_t tuple_size = std::tuple_size<std::decay_t<Tuple>>::value;
      26             :   static_assert(
      27             :       Start <= Stop and Stop <= tuple_size,
      28             :       "'Start' and 'Stop' must satisfy Start <= Stop <= size of 'Tuple'");
      29             :   return tuple_impl_detail::slice_impl<Start>(
      30             :       std::forward<Tuple>(tuple), std::make_index_sequence<Stop - Start>{});
      31             : }
      32             : 
      33             : /// \ingroup UtilitiesGroup
      34             : /// The first `Size` elements in `tuple`
      35             : template <size_t Size, typename Tuple>
      36           1 : constexpr auto tuple_head(Tuple&& tuple) {
      37             :   constexpr size_t tuple_size = std::tuple_size<std::decay_t<Tuple>>::value;
      38             :   static_assert(Size <= tuple_size,
      39             :                 "'Size' must not exceed the size of 'Tuple'");
      40             :   return tuple_slice<0, Size>(std::forward<Tuple>(tuple));
      41             : }
      42             : 
      43             : /// \ingroup UtilitiesGroup
      44             : /// The last `Size` elements in `tuple`
      45             : template <size_t Size, typename Tuple>
      46           1 : constexpr auto tuple_tail(Tuple&& tuple) {
      47             :   constexpr size_t tuple_size = std::tuple_size<std::decay_t<Tuple>>::value;
      48             :   static_assert(Size <= tuple_size,
      49             :                 "'Size' must not exceed the size of 'Tuple'");
      50             :   return tuple_slice<tuple_size - Size, tuple_size>(std::forward<Tuple>(tuple));
      51             : }

Generated by: LCOV version 1.14