BLT/include/blt/iterator/iterator.h

59 lines
1.8 KiB
C
Raw Permalink Normal View History

#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef BLT_ITERATOR_H
#define BLT_ITERATOR_H
2024-09-30 02:38:36 -04:00
#include <blt/iterator/common.h>
2024-09-28 16:50:19 -04:00
#include <blt/iterator/zip.h>
2024-10-01 16:46:15 -04:00
#include <blt/iterator/enumerate.h>
#include <type_traits>
#include <iterator>
2024-09-27 18:18:02 -04:00
#include <tuple>
namespace blt
{
template<typename T>
2024-10-01 16:46:15 -04:00
static inline auto iterate(T& container)
{
2024-10-01 16:46:15 -04:00
return iterator::iterator_container<decltype(container.begin())>{container.begin(), container.end()};
}
2024-09-26 02:53:11 -04:00
template<typename T>
2024-10-01 16:46:15 -04:00
static inline auto iterate(const T& container)
2024-09-27 15:12:08 -04:00
{
2024-10-01 16:46:15 -04:00
return iterator::iterator_container<decltype(container.begin())>{container.begin(), container.end()};
2024-09-27 15:12:08 -04:00
}
2024-09-27 18:18:02 -04:00
2024-10-01 16:46:15 -04:00
template<typename T, blt::size_t size>
static inline auto iterate(const T(& container)[size])
2024-09-27 15:12:08 -04:00
{
2024-10-01 16:46:15 -04:00
return iterator::iterator_container<decltype(container.begin())>{&container[0], &container[size]};
2024-09-27 15:12:08 -04:00
}
2024-09-27 18:18:02 -04:00
2024-10-01 16:46:15 -04:00
template<typename T, blt::size_t size>
static inline auto iterate(T(& container)[size])
2024-09-27 15:12:08 -04:00
{
2024-10-01 16:46:15 -04:00
return iterator::iterator_container<decltype(container.begin())>{&container[0], &container[size]};
2024-09-27 15:12:08 -04:00
}
2024-10-01 16:46:15 -04:00
}
#endif //BLT_ITERATOR_H