rhubarb-lip-sync/src/pairs.h

22 lines
685 B
C
Raw Normal View History

2016-05-12 19:21:25 +00:00
#pragma once
#include <vector>
template<typename TCollection>
std::vector<std::pair<typename TCollection::value_type, typename TCollection::value_type>> getPairs(const TCollection& collection) {
using TElement = typename TCollection::value_type;
using TPair = std::pair<TElement, TElement>;
2016-06-16 07:36:33 +00:00
using TIterator = typename TCollection::const_iterator;
2016-05-12 19:21:25 +00:00
auto begin = collection.begin();
auto end = collection.end();
2016-06-16 07:36:33 +00:00
if (begin == end || ++TIterator(begin) == end) {
2016-05-12 19:21:25 +00:00
return std::vector<TPair>();
}
std::vector<TPair> result;
2016-06-16 07:36:33 +00:00
for (auto first = begin, second = ++TIterator(begin); second != end; ++first, ++second) {
2016-05-12 19:21:25 +00:00
result.push_back(TPair(*first, *second));
}
return result;
}