kyopro-lib

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:question: Input tuples with index
(Mylib/IO/input_tuples_with_index.cpp)

Operations

Requirements

Notes

Problems

References

Depends on

Verified with

Code

#pragma once
#include <initializer_list>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>
#include "Mylib/IO/input_tuple.cpp"

namespace haar_lib {
  template <typename... Args>
  class InputTuplesWithIndex {
    struct iter {
      using value_type = std::tuple<int, Args...>;
      value_type value;
      bool fetched = false;
      int N;
      int c = 0;

      value_type operator*() {
        if (not fetched) {
          std::tuple<Args...> temp;
          std::cin >> temp;
          value = std::tuple_cat(std::make_tuple(c), temp);
        }
        return value;
      }

      void operator++() {
        ++c;
        fetched = false;
      }

      bool operator!=(iter &) const {
        return c < N;
      }

      iter(int N) : N(N) {}
    };

    int N;

  public:
    InputTuplesWithIndex(int N) : N(N) {}

    iter begin() const { return iter(N); }
    iter end() const { return iter(N); }
  };

  template <typename... Args>
  auto input_tuples_with_index(int N) {
    return InputTuplesWithIndex<Args...>(N);
  }
}  // namespace haar_lib
#line 2 "Mylib/IO/input_tuples_with_index.cpp"
#include <initializer_list>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>
#line 6 "Mylib/IO/input_tuple.cpp"

namespace haar_lib {
  template <typename T, size_t... I>
  static void input_tuple_helper(std::istream &s, T &val, std::index_sequence<I...>) {
    (void) std::initializer_list<int>{(void(s >> std::get<I>(val)), 0)...};
  }

  template <typename T, typename U>
  std::istream &operator>>(std::istream &s, std::pair<T, U> &value) {
    s >> value.first >> value.second;
    return s;
  }

  template <typename... Args>
  std::istream &operator>>(std::istream &s, std::tuple<Args...> &value) {
    input_tuple_helper(s, value, std::make_index_sequence<sizeof...(Args)>());
    return s;
  }
}  // namespace haar_lib
#line 8 "Mylib/IO/input_tuples_with_index.cpp"

namespace haar_lib {
  template <typename... Args>
  class InputTuplesWithIndex {
    struct iter {
      using value_type = std::tuple<int, Args...>;
      value_type value;
      bool fetched = false;
      int N;
      int c = 0;

      value_type operator*() {
        if (not fetched) {
          std::tuple<Args...> temp;
          std::cin >> temp;
          value = std::tuple_cat(std::make_tuple(c), temp);
        }
        return value;
      }

      void operator++() {
        ++c;
        fetched = false;
      }

      bool operator!=(iter &) const {
        return c < N;
      }

      iter(int N) : N(N) {}
    };

    int N;

  public:
    InputTuplesWithIndex(int N) : N(N) {}

    iter begin() const { return iter(N); }
    iter end() const { return iter(N); }
  };

  template <typename... Args>
  auto input_tuples_with_index(int N) {
    return InputTuplesWithIndex<Args...>(N);
  }
}  // namespace haar_lib
Back to top page